Update multiple records and fields problem

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Update multiple records and fields problem

    I need to update a table based on input into text fields on a form
    The html page has two columns, Responsibility # and Responsibility
    The Res. # has an number (like 1,2,3) and the Responsibilty is string.

    Everything displays perfectly but I need the user to be able to update
    both fields. So he could rearrange the numbers and also change the
    text of any of them.

    I have done plenty of update queries, but none of this variety. So
    far, I have used a loop to give each textbox a diff. name and tried
    passing my update query page the number of rows. Then loop through
    that and try to update for each row where the RESP_NUM ="whaterver".

    dim val
    dim iloop
    for iloop = 1 to count
    val="RESP"&iloop
    strSQLsaveresp = "UPDATE RESP SET " _
    & "RESP = '" & CStr(Replace(Request.Form(val),"'", "''")) & "' " _
    & "WHERE (POSCODE = '" & id & "' AND RESP_NUM = '" &
    Request.Form("RESP_NUM") & "')"

    cnnDBEdit.Execute(strSQLsaveresp)
    next

    (count is passed and is the number of records displayed on the page)
    Textboxes are name resp1, resp2, etc.

    That code is obviously not gonna work, but.....

    The "Responsibilities" table is set up as follow
    |POSCODE|RESP_NUM|RESP|
    -----------------------
    |*70362 | 1 |this is responsibility #1..yada
    |*70362 | 2 |this is responsibility #2..yada

    and on for a variable number of responsibilites per poscode
    .......

    This is intranet and doesnt necessarily need to check if each record
    has been changed before updating. Just update keeping the resp_num
    and resp matching after the user changes either box on the page.

    Cant find any tutorials that help do this. Some do multiple records,
    but not multiple fields and records.

    Thanks everybody!
    J.D. Buehls Guest

  2. Similar Questions and Discussions

    1. update multiple records
      I'm trying to to update multiple records with a drop down. My update statment updates all selected records with all selected choices. I get for...
    2. update multiple records in multiple tables from one form
      hello I have been trying to run multiple update queries based on the data entered by user. Brief background: I am fetching data from various...
    3. Updating Multiple records fields in a database atonce
      Is it correct that there is no user interaction on these forms? I didn't see a submit button. Or does someone click on a submit button to get to...
    4. How to insert multiple records to the same table with a multi-fields form
      Hi all, is it possibile to insert multiple records in the same table? I imagine to build a multi-rows form, with the same number of fields per...
    5. ANN: Update Multiple Records in ASP
      I've put together an article and demo on how to batch update records in a recordset: ...
  3. #2

    Default Re: Update multiple records and fields problem

    UPDATE takes more than one parameter :

    [url]http://www.google.com/search?sourceid=navclient&q=SQL+Update[/url]

    "J.D. Buehls" wrote:
    > I need to update a table based on input into text fields on a form
    > The html page has two columns, Responsibility # and Responsibility
    > The Res. # has an number (like 1,2,3) and the Responsibilty is string.
    >
    > Everything displays perfectly but I need the user to be able to update
    > both fields. So he could rearrange the numbers and also change the
    > text of any of them.
    >
    > I have done plenty of update queries, but none of this variety. So
    > far, I have used a loop to give each textbox a diff. name and tried
    > passing my update query page the number of rows. Then loop through
    > that and try to update for each row where the RESP_NUM ="whaterver".
    >
    > dim val
    > dim iloop
    > for iloop = 1 to count
    > val="RESP"&iloop
    > strSQLsaveresp = "UPDATE RESP SET " _
    > & "RESP = '" & CStr(Replace(Request.Form(val),"'", "''")) & "' " _
    > & "WHERE (POSCODE = '" & id & "' AND RESP_NUM = '" &
    > Request.Form("RESP_NUM") & "')"
    >
    > cnnDBEdit.Execute(strSQLsaveresp)
    > next
    >
    > (count is passed and is the number of records displayed on the page)
    > Textboxes are name resp1, resp2, etc.
    >
    > That code is obviously not gonna work, but.....
    >
    > The "Responsibilities" table is set up as follow
    > |POSCODE|RESP_NUM|RESP|
    > -----------------------
    > |*70362 | 1 |this is responsibility #1..yada
    > |*70362 | 2 |this is responsibility #2..yada
    >
    > and on for a variable number of responsibilites per poscode
    > ......
    >
    > This is intranet and doesnt necessarily need to check if each record
    > has been changed before updating. Just update keeping the resp_num
    > and resp matching after the user changes either box on the page.
    >
    > Cant find any tutorials that help do this. Some do multiple records,
    > but not multiple fields and records.
    >
    > Thanks everybody!
    Greg Griffiths Guest

  4. #3

    Default Re: Update multiple records and fields problem

    Does this really answer my question? I mean, I can do update queries
    no problem, like this one in my page:

    strSQLsavegeneral = "UPDATE SUMMARY SET " _ & "USED_ EQUIP = '"
    & CStr(Replace(Request.Form"USED_EQUIP"), "'", "''")) & "', " _
    & "USED_MATLS = '" & CStr(Replace Request.Form "USED_MATLS"),
    "'", "''")) & "', " _
    & "USED_TOOLS = '" & CStr(Replace(Request.Form "USED_TOOLS"),
    "'", "''")) & "' " _
    & "WHERE (POSCODE = '" & id & "')"

    I mean that is really simple, but what if you have a 2 by X number
    layout of textboxes and you need to update each row of textboxes to a
    specific record (where they are number 1 through X, which is the value
    put into the left textbox). That is not as straightforward as the
    basic update you linked to I believe.

    Thanks again.


    Greg Griffiths <greg2@surfaid.org> wrote in message news:<40215444.A4AB3ED0@surfaid.org>...
    > UPDATE takes more than one parameter :
    >
    > [url]http://www.google.com/search?sourceid=navclient&q=SQL+Update[/url]
    >
    > "J.D. Buehls" wrote:
    >
    > > I need to update a table based on input into text fields on a form
    > > The html page has two columns, Responsibility # and Responsibility
    > > The Res. # has an number (like 1,2,3) and the Responsibilty is string.
    > >
    > > Everything displays perfectly but I need the user to be able to update
    > > both fields. So he could rearrange the numbers and also change the
    > > text of any of them.
    > >
    > > I have done plenty of update queries, but none of this variety. So
    > > far, I have used a loop to give each textbox a diff. name and tried
    > > passing my update query page the number of rows. Then loop through
    > > that and try to update for each row where the RESP_NUM ="whaterver".
    > >
    > > dim val
    > > dim iloop
    > > for iloop = 1 to count
    > > val="RESP"&iloop
    > > strSQLsaveresp = "UPDATE RESP SET " _
    > > & "RESP = '" & CStr(Replace(Request.Form(val),"'", "''")) & "' " _
    > > & "WHERE (POSCODE = '" & id & "' AND RESP_NUM = '" &
    > > Request.Form("RESP_NUM") & "')"
    > >
    > > cnnDBEdit.Execute(strSQLsaveresp)
    > > next
    > >
    > > (count is passed and is the number of records displayed on the page)
    > > Textboxes are name resp1, resp2, etc.
    > >
    > > That code is obviously not gonna work, but.....
    > >
    > > The "Responsibilities" table is set up as follow
    > > |POSCODE|RESP_NUM|RESP|
    > -----------------------
    > > |*70362 | 1 |this is responsibility #1..yada
    > > |*70362 | 2 |this is responsibility #2..yada
    > >
    > > and on for a variable number of responsibilites per poscode
    > > ......
    > >
    > > This is intranet and doesnt necessarily need to check if each record
    > > has been changed before updating. Just update keeping the resp_num
    > > and resp matching after the user changes either box on the page.
    > >
    > > Cant find any tutorials that help do this. Some do multiple records,
    > > but not multiple fields and records.
    > >
    > > Thanks everybody!
    J.D. Buehls Guest

  5. #4

    Default Re: Update multiple records and fields problem

    "J.D. Buehls" <bulldawgfan12000@yahoo.com> wrote in message
    news:733c346f.0402040955.180bbfc7@posting.google.c om...
    > I need to update a table based on input into text fields on a form
    > The html page has two columns, Responsibility # and Responsibility
    > The Res. # has an number (like 1,2,3) and the Responsibilty is string.
    >
    > Everything displays perfectly but I need the user to be able to update
    > both fields. So he could rearrange the numbers and also change the
    > text of any of them.

    Two thoughts:


    1) Don't store each Responsibility as a distinct row. Concatenate (Join)
    all Responsibilities in a Memo field. Their relative position is their
    "Responsibility #".


    2) Use one text field to insert entries into a "multiple select" form
    field. Update the table from the drop-down entries.

    For updating you could add up and down arrows calling JavaScript functions
    to reposition entries.

    Set the "size=" to the maximum number of entries so they're visible and use
    "style=" to set the width.



    McKirahan Guest

  6. #5

    Default Re: Update multiple records and fields problem

    "J.D. Buehls" <bulldawgfan12000@yahoo.com> wrote in message
    news:733c346f.0402040955.180bbfc7@posting.google.c om...
    > I need to update a table based on input into text fields on a form
    > The html page has two columns, Responsibility # and Responsibility
    > The Res. # has an number (like 1,2,3) and the Responsibilty is string.
    >
    > Everything displays perfectly but I need the user to be able to update
    > both fields. So he could rearrange the numbers and also change the
    > text of any of them.
    >
    > I have done plenty of update queries, but none of this variety. So
    > far, I have used a loop to give each textbox a diff. name and tried
    > passing my update query page the number of rows. Then loop through
    > that and try to update for each row where the RESP_NUM ="whaterver".
    >
    > dim val
    > dim iloop
    > for iloop = 1 to count
    > val="RESP"&iloop
    > strSQLsaveresp = "UPDATE RESP SET " _
    > & "RESP = '" & CStr(Replace(Request.Form(val),"'", "''")) & "' " _
    > & "WHERE (POSCODE = '" & id & "' AND RESP_NUM = '" &
    > Request.Form("RESP_NUM") & "')"
    >
    > cnnDBEdit.Execute(strSQLsaveresp)
    > next
    >
    > (count is passed and is the number of records displayed on the page)
    > Textboxes are name resp1, resp2, etc.
    >
    > That code is obviously not gonna work, but.....
    >
    > The "Responsibilities" table is set up as follow
    > |POSCODE|RESP_NUM|RESP|
    > -----------------------
    > |*70362 | 1 |this is responsibility #1..yada
    > |*70362 | 2 |this is responsibility #2..yada
    >
    > and on for a variable number of responsibilites per poscode
    > ......
    >
    > This is intranet and doesnt necessarily need to check if each record
    > has been changed before updating. Just update keeping the resp_num
    > and resp matching after the user changes either box on the page.
    >
    > Cant find any tutorials that help do this. Some do multiple records,
    > but not multiple fields and records.
    >
    > Thanks everybody!
    Assuming MS SQL Server, here's what the query would look like:

    UPDATE
    R
    SET
    R.RESP= T.RESP
    FROM
    RESP AS R,
    (
    SELECT 1 AS RESP_NUM, 'this is responsibility #1..yada' AS RESP UNION
    ALL
    SELECT 2, 'this is responsibility #2..yada'
    ) AS T
    WHERE
    R.POSCODE = '*70362' AND
    R.RESP_NUM = T.RESP_NUM

    Constructing the query string in via ASP is left as an exercise for the
    user.

    HTH
    -Chris Hohmann














    Chris Hohmann Guest

  7. #6

    Default Re: Update multiple records and fields problem

    "Chris Hohmann" <nospam@thankyou.com> wrote in message
    news:%23bdZLvE7DHA.2924@tk2msftngp13.phx.gbl...
    > "J.D. Buehls" <bulldawgfan12000@yahoo.com> wrote in message
    > news:733c346f.0402040955.180bbfc7@posting.google.c om...
    > > I need to update a table based on input into text fields on a form
    > > The html page has two columns, Responsibility # and Responsibility
    > > The Res. # has an number (like 1,2,3) and the Responsibilty is
    string.
    > >
    > > Everything displays perfectly but I need the user to be able to
    update
    > > both fields. So he could rearrange the numbers and also change the
    > > text of any of them.
    > >
    > > I have done plenty of update queries, but none of this variety. So
    > > far, I have used a loop to give each textbox a diff. name and tried
    > > passing my update query page the number of rows. Then loop through
    > > that and try to update for each row where the RESP_NUM ="whaterver".
    > >
    > > dim val
    > > dim iloop
    > > for iloop = 1 to count
    > > val="RESP"&iloop
    > > strSQLsaveresp = "UPDATE RESP SET " _
    > > & "RESP = '" & CStr(Replace(Request.Form(val),"'", "''")) & "' " _
    > > & "WHERE (POSCODE = '" & id & "' AND RESP_NUM = '" &
    > > Request.Form("RESP_NUM") & "')"
    > >
    > > cnnDBEdit.Execute(strSQLsaveresp)
    > > next
    > >
    > > (count is passed and is the number of records displayed on the page)
    > > Textboxes are name resp1, resp2, etc.
    > >
    > > That code is obviously not gonna work, but.....
    > >
    > > The "Responsibilities" table is set up as follow
    > > |POSCODE|RESP_NUM|RESP|
    > > -----------------------
    > > |*70362 | 1 |this is responsibility #1..yada
    > > |*70362 | 2 |this is responsibility #2..yada
    > >
    > > and on for a variable number of responsibilites per poscode
    > > ......
    > >
    > > This is intranet and doesnt necessarily need to check if each record
    > > has been changed before updating. Just update keeping the resp_num
    > > and resp matching after the user changes either box on the page.
    > >
    > > Cant find any tutorials that help do this. Some do multiple
    records,
    > > but not multiple fields and records.
    > >
    > > Thanks everybody!
    >
    > Assuming MS SQL Server, here's what the query would look like:
    >
    > UPDATE
    > R
    > SET
    > R.RESP= T.RESP
    > FROM
    > RESP AS R,
    > (
    > SELECT 1 AS RESP_NUM, 'this is responsibility #1..yada' AS RESP UNION
    > ALL
    > SELECT 2, 'this is responsibility #2..yada'
    > ) AS T
    > WHERE
    > R.POSCODE = '*70362' AND
    > R.RESP_NUM = T.RESP_NUM
    >
    > Constructing the query string in via ASP is left as an exercise for
    the
    > user.
    >
    > HTH
    > -Chris Hohmann
    Your posted code indicates that RESP_NUM is a string. Here's the revised
    query:
    UPDATE
    R
    SET
    R.RESP= T.RESP
    FROM
    RESP AS R,
    (
    SELECT '1' AS RESP_NUM, 'this is responsibility #1..yada' AS RESP UNION
    ALL
    SELECT '2', 'this is responsibility #2..yada'
    ) AS T
    WHERE
    R.POSCODE = '*70362' AND
    R.RESP_NUM = T.RESP_NUM

    HTH
    -Chris Hohmann


    Chris Hohmann Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139