473,796 Members | 2,462 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update Multiple Rows In A Form

Part No Description Quantity
45643 Random part 10
45678 Another Random part 7
98944 And another 1
<submit button>
The above is an example of some data I am displaying in a
form on an ASP page. I need to allow the users to edit
any of the rows displayed and submit the changes back to
the database.

The problem I have is that I'm not entirely sure how to
determine which rows were changed (if any). And then do
the appropriate update. I've thought about putting an
edit button at the end of each row and forwarding the user
to another page which which deals with the corresponding
row on an individual basis. But this feels a bit long
winded. Can anyone suggest a better way?

TIA,

Colin
Jul 19 '05 #1
2 2576
You could update all rows regardless although that's a bit gash. You don't
say what the user is updating - assuming that it's the quantity field you
can pass each current quantity through to the processor in a hidden form
field. Each hidden field's name should be some derivation of the ID of the
product. When you're processing the form submission, generate a list of the
products that may have been updated and then for each product, request the
new value from it's text control, and the old value from the hidden field
(deriving names as required), and if the two values are different, update
that product record.

Cheers,

Alan

"Colin Steadman" <an*******@disc ussions.microso ft.com> wrote in message
news:22******** *************** ******@phx.gbl. ..
Part No Description Quantity
45643 Random part 10
45678 Another Random part 7
98944 And another 1
<submit button>
The above is an example of some data I am displaying in a
form on an ASP page. I need to allow the users to edit
any of the rows displayed and submit the changes back to
the database.

The problem I have is that I'm not entirely sure how to
determine which rows were changed (if any). And then do
the appropriate update. I've thought about putting an
edit button at the end of each row and forwarding the user
to another page which which deals with the corresponding
row on an individual basis. But this feels a bit long
winded. Can anyone suggest a better way?

TIA,

Colin

Jul 19 '05 #2
"Alan Howard" <Xa***********@ Xparadise.net.n zX> wrote in message news:<#f******* *******@TK2MSFT NGP12.phx.gbl>. ..
You could update all rows regardless although that's a bit gash.

Agreed.
You don't
say what the user is updating -
It could be any of the fields I've shown in my example, although there
are a whole load more of them.

assuming that it's the quantity field you
can pass each current quantity through to the processor in a hidden form
field. Each hidden field's name should be some derivation of the ID of the
product. When you're processing the form submission, generate a list of the
products that may have been updated and then for each product, request the
new value from it's text control, and the old value from the hidden field
(deriving names as required), and if the two values are different, update
that product record.


This is what I've decided to try and do. I'm giving each input box a
unique name based on the field name and row number with '_new' stuck
on the end. Under this I've got a hidden field setup the same way but
ending in '_old'. Like this (looks a bit messy in google):

<%
rowNumber = 1

'Main table
Do While Not rs2.EOF
response.write "<tr>"
For columnNumber = 0 To rs2.Fields.Coun t -1
Select Case LCase(rs2.Field s(columnNumber) .Name)
Case "invoice_no "
Case Else
response.write " <td>"
response.write " <input type=text name='" & Right("00000"
& rowNumber, 5) & rs2.Fields(colu mnNumber).Name & "_new" & "' value='"
& rs2.Fields(colu mnNumber).Value & "'>"

response.write " <input type=hidden name='" & Right("00000"
& rowNumber, 5) & rs2.Fields(colu mnNumber).Name & "_old" & "' value='"
& rs2.Fields(colu mnNumber).Value & "'>"
response.write " </td>"
End Select
Next
response.write "</tr>"
rs2.MoveNext
rowNumber = rowNumber + 1
Loop
%>

Then on the page which I'm submitting to I've written the For.. Next
loop copied below which compares old and new values and generates SQL
accordingly. I'm planning to begin a transaction before processing
this loop, and if all goes well and none of the updates generate an
error I'll do the commit at the end. Not tested it yet, but the SQL
its generating looks good.
For Each Item In Request.QuerySt ring
Select Case Item
Case "submit.x", "submit.y"
Case Else
If Right(Item,3) = "old" Then
newValue = Left(Item,Len(I tem)-4) & "_new"
If Request.Queryst ring(Item) <> Request.Queryst ring(newValue)
Then
fieldName = Mid(Item, 6, Len(Item) - 9)
sql = "update table set " & fieldName & " = " &
Request.Queryst ring(newValue) & " where " & fieldName & " = " &
Request.Queryst ring(Item) & " and invoice_no = '" &
Request.Queryst ring("invoice_n umber") & "'"
response.write "<br>" & sql
End If
End If
End Select
Next
Colin
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6140
by: shank | last post by:
Visually, the page will look somewhat like a spreadsheet. It could have hundreds of records (rows) displayed. I want to enable the user to edit any one or any number of records and any fields, then click a save button to UPDATE the SQL table. I'd like to use stored procedures if possible. How is this done? Where do I start? thanks
2
31130
by: Rima | last post by:
I have the following two tables : table a (commit_id, capital_market_id, chg_lst_date ) table b (b_seq_id,
7
4102
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
6
2429
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid, then an expanded version that will work on all orderids with a specific customerinvoiceid as a parameter. I'm sure appropriate joins will handle it, but I'm not making any headway, everything comes back with multiple tuple selected for update...
0
5828
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new records into the database. No updates to existing entries, no deletions, and no display
9
12989
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from northwind database that has an employees, orders, and order details. the following are the 3 tables in my sql database students schyrsem
11
2252
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to reflect that the 3 items have been deleted only to discover that the 3 items appear, however when I click on them to display their information which runs a datareader over the same database it appears that the data has now gone. I wondered whether...
8
2698
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
5
7472
stepterr
by: stepterr | last post by:
I have a form that is built based on a query. Everything is working except when I submit the form the radio buttons are only updating the first row in my database. dcategory and dthumbnail are two radio buttons that I have for each one of the rows in the table. I've tried using a hidden input object for each of the radio button groups to store the values in but clearly I'm having a mental block because I can't get that to work right either. So...
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10457
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.