Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Table Via Tableadapter

Status
Not open for further replies.

besto1a

Programmer
Aug 20, 2006
41
GB
I have a DataGrid that is populated with the a tableadptor.

I want to change things in the datagrid and use the tableadaptors "Update" meothod to commit the change in the datagrid to the SQL table, How do i do this??
 
To use the .update, you need first to set the table's adapter UpdateCommand.
 
How do you set the update Command and what sghould you set it to ?
 
I've king of got this to work but come accros amother problem.

In my Data set I have fields User and user name, if I chnage a username on one row and call the .update method to commeit the chnage from the ds to the sql table, All record in that table update with the new user nameI have entered.

All i want to do is amedn the record thati have chnaged in teh dataset
 
It sounds like the update command does not have a WHERE section

Should be something like:

UPDATE tablename SET USER = ?, USERNAME = ? WHERE USER = ? AND USERNAME = ?

 
Ah, but if i have a ds that has 100 rows, and i only changes 1 row do i still have to loop through the dataset and call the update method for every record?
 
Ah, but if i have a ds that has 100 rows, and i only changes 1 row do i still have to loop through the dataset and call the update method for every record?

No.

The dataadapter should update the table with only the rows which are affected.
It will remove the deleted rows, insert the new rows and update the changed rows.
(All providing the ds and adapter are setup correctly)

for example:

dim int as integer = myAdapter.update(ds, "TableName")

int will return number of affected rows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top