Updating database with changes

G

Guest

hi!!

how am i supposed to update the db witht he changes the user make in webpage

am trying to make a simple page that have a grid bound to a table

the user can delete,add or update the grid

how do i get the changes into the database

after the page is loaded the dataset is gone so the databinding only works for reading

do i really have to make an array and handle the updating myself

regard
geir sann
 
R

Rick Spiewak

If you want to do updates, you should use a dataset. It sounds like you may
be using a datareader - if so, switch to a dataset.
To update using a dataset, make changes to the datatable during the update
event on the datagrid. Then, use the GetChanges method on the datatable to
construct a new table with the changes. Call the appropriate update method
for each changed row - insert, update, or delete.
 
A

Alec MacLean

Geir,

There are loads of examples on various specialist websites: www.123aspx.com
is a good place to bookmark.
I can tell you from my own experience I didn't want to use the default
asp.net methods of working with the datagrid, so I rolled my own after
learning from Microsoft and other examples.

Basically, I use stored procedures for all db read/write operations and do
all grid databinding in custom (VB) procedures.

So a page's code-behind might look something like:

Sub page_load (...) Handles ...
if Not page.ispostback then
'If required, ensure user is authenticated/authorised

'Get default data for display...
me.BindMyGrid()

end if

end sub


private sub BindMyGrid()
'Do the bind routine...
'Set up a connection to db and retrieve required data
'See my response posting for Tracey for example connection method:
'Re: Urgent: I can't update database with SqlCommand
' '
end sub

private sub cmdSaveData(....) Handles ...
'Respond to the command button being clicked
'Validate all input
'I use try-catch statements for validation...
'Again, see the above message thread for my example technique for
validation and attaching values to send to the sproc/db
'
end sub

HTH
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top