update multiple rows

S

shank

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
 
H

Harag

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

Firstly you need to think about the front end a bit more and who are
the users that will be using it imho (lan, intranet, just you, couple
admin people or the millions on the web?)

Look at not displaying 100's of rows but only 10-30 or so at a time
for this you would need some sort of paging stored proc.

http://www.aspfaq.com/2120

check out the last version listed using @@rowcount by Chris Hohmann
for this.


Also saving the info... will it be one save button at the bottom? or
one for each row ?

eg

<form ...>
line 1 ID: <input type="hidden" name="memID" value="1234">
line 1 name: <input type="text" name="memName" value="fred
flintstone">
line 1 age: <input type="text" name="memAge" value="32">

line 2 ID: <input type="hidden" name="memID" value="1235">
line 2 name: <input type="text" name="memName" value="Wilma
flintstone">
line 2 age: <input type="text" name="memAge" value="28">

line 3 ID: <input type="hidden" name="memID" value="1236">
line 3 name: <input type="text" name="memName" value="dino
flintstone">
line 3 age: <input type="text" name="memAge" value="4">

<input type="submit" value="save all">
</form>

by doing the above all the above info will be sent to the server in 3
"arrays"

response.form("memID") would be "1234, 1235, 1236"
response.form("memName") "fred flintstone, wilma flintstone, dino ..."
response.form("memAge") "32, 28, 4"

which you can then send to the DB stored proc and get that to update
the info. Since SQL servers dont have arrays as such then you would
need to check out the following page:

http://www.sommarskog.se/arrays-in-sql.html



If you have a save button for each entry.

<form ...>
line 1 ID: <input type="hidden" name="memID" value="1234">
line 1 name: <input type="text" name="memName" value="fred
flintstone">
line 1 age: <input type="text" name="memAge" value="32">
<input type="submit" value="save">
</form>
<form ...>
line 2 ID: <input type="hidden" name="memID" value="1235">
line 2 name: <input type="text" name="memName" value="Wilma
flintstone">
line 2 age: <input type="text" name="memAge" value="28">
<input type="submit" value="save">
</form>
<form ...>
line 3 ID: <input type="hidden" name="memID" value="1236">
line 3 name: <input type="text" name="memName" value="dino
flintstone">
line 3 age: <input type="text" name="memAge" value="4">
<input type="submit" value="save">
</form>


Then the user will have to click it for each line he has changed. and
one line of info will be sent to the DB and updated, accordingly.


Next - the result... where to send the "save" result. well. since it
has to go to the server to send the info and to update the db, how are
you going to tell the user this has worked ok. Personally when I do
forms I (near) always put the DB updating code in the same for as the
displaying code. so the code for the above would look like this:


FILENAME.ASP.


1) check to see if a form has been posted to this file.
2) if not 1 skil step 3
3a) if 1 then run function "updateDB()" or whatever.
3b) if 2 ok tell user "info saved" or store in variable for later
display

4) get page data(ie the 20 rows to display)
5) display page info to user.
6) EOF.



Other things to think about on the frontend, is what javascript you
might want to make it easier for the user. eg. how about disabling the
save button and only enable it when the user actually changes some
text? or if your doing a SaveALL then you could have another hidden
entry like the MemID which is just 1 or a 0 and set it to 1 when the
user has changed any info, then in the DB stored proc you only need to
update the rows where this value is a 1.


good luck.

HTH.

Al
 
S

shank

Harag said:
Firstly you need to think about the front end a bit more and who are
the users that will be using it imho (lan, intranet, just you, couple
admin people or the millions on the web?)

Look at not displaying 100's of rows but only 10-30 or so at a time
for this you would need some sort of paging stored proc.

http://www.aspfaq.com/2120

check out the last version listed using @@rowcount by Chris Hohmann
for this.


Also saving the info... will it be one save button at the bottom? or
one for each row ?

eg

<form ...>
line 1 ID: <input type="hidden" name="memID" value="1234">
line 1 name: <input type="text" name="memName" value="fred
flintstone">
line 1 age: <input type="text" name="memAge" value="32">

line 2 ID: <input type="hidden" name="memID" value="1235">
line 2 name: <input type="text" name="memName" value="Wilma
flintstone">
line 2 age: <input type="text" name="memAge" value="28">

line 3 ID: <input type="hidden" name="memID" value="1236">
line 3 name: <input type="text" name="memName" value="dino
flintstone">
line 3 age: <input type="text" name="memAge" value="4">

<input type="submit" value="save all">
</form>

by doing the above all the above info will be sent to the server in 3
"arrays"

response.form("memID") would be "1234, 1235, 1236"
response.form("memName") "fred flintstone, wilma flintstone, dino ..."
response.form("memAge") "32, 28, 4"

which you can then send to the DB stored proc and get that to update
the info. Since SQL servers dont have arrays as such then you would
need to check out the following page:

http://www.sommarskog.se/arrays-in-sql.html



If you have a save button for each entry.

<form ...>
line 1 ID: <input type="hidden" name="memID" value="1234">
line 1 name: <input type="text" name="memName" value="fred
flintstone">
line 1 age: <input type="text" name="memAge" value="32">
<input type="submit" value="save">
</form>
<form ...>
line 2 ID: <input type="hidden" name="memID" value="1235">
line 2 name: <input type="text" name="memName" value="Wilma
flintstone">
line 2 age: <input type="text" name="memAge" value="28">
<input type="submit" value="save">
</form>
<form ...>
line 3 ID: <input type="hidden" name="memID" value="1236">
line 3 name: <input type="text" name="memName" value="dino
flintstone">
line 3 age: <input type="text" name="memAge" value="4">
<input type="submit" value="save">
</form>


Then the user will have to click it for each line he has changed. and
one line of info will be sent to the DB and updated, accordingly.


Next - the result... where to send the "save" result. well. since it
has to go to the server to send the info and to update the db, how are
you going to tell the user this has worked ok. Personally when I do
forms I (near) always put the DB updating code in the same for as the
displaying code. so the code for the above would look like this:


FILENAME.ASP.


1) check to see if a form has been posted to this file.
2) if not 1 skil step 3
3a) if 1 then run function "updateDB()" or whatever.
3b) if 2 ok tell user "info saved" or store in variable for later
display

4) get page data(ie the 20 rows to display)
5) display page info to user.
6) EOF.



Other things to think about on the frontend, is what javascript you
might want to make it easier for the user. eg. how about disabling the
save button and only enable it when the user actually changes some
text? or if your doing a SaveALL then you could have another hidden
entry like the MemID which is just 1 or a 0 and set it to 1 when the
user has changed any info, then in the DB stored proc you only need to
update the rows where this value is a 1.


good luck.

HTH.

Al
-----------------------
There will only be about 6 users who can access the page. I was planning on
one save button. But after considering all the possibilities, I think it's
best if I just let them connect with ODBC and use Access as a frontend on
everyone's desktop. The end effort is to enable these 6 people to edit one
single table of data without downloading and passing it around the country
for everyone's edits. Also, they will need the capability of running
reports. Access will be easiest to handle this.

I still want to try the above though. Your suggestions will help on other
projects.
thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top