Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I need help (of course) :)

how to save changes made in datagridview rows on button click

I have
tabledatadapter daData
dataset dsData
binding source DataBS

this code
C#
daData.SelectCommand = new SqlCommand("SELECT * from DataDetails", cs);
dsData.Clear();
daData.Fill(dsData);

DataBS.DataSource = dsData.Tables[0];


and for update on buttonclick
C#
daData.Update(dsData);


but it gives me this error
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.


ideas ideas ideas
Posted
Updated 10-Sep-12 0:46am
v2
Comments
Karthik Harve 10-Sep-12 6:45am    
Do you want to update back in database, or just in DataGridView ?

I hope it helps:
C#
daData.UpdateCommand = new SqlCommandBuilder( daData).GetUpdateCommand();
 
Share this answer
 
Comments
shonezi 10-Sep-12 7:12am    
nothing happens
[no name] 10-Sep-12 11:00am    
Where did you use that?
Hi ,
Check this

C#
daData.Update(dsData);
        daData.AcceptChanges();

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
shonezi 10-Sep-12 8:07am    
same error again, whats wrong Mohamed with this, it should work
Mohamed Mitwalli 10-Sep-12 15:04pm    
try this
daData.Update(dsData.Tables["tablename"]);
daData.AcceptChanges();

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900