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

I have a query regarding updating datagridview to database.
I have a datagridview to the form, which filled providing datatable as a source.
Now I want to edit and update the same datagrid.
It is editing properly but at the time of update there is no error and database is also the same.
I have used dataset , bindingsource and dataadapter on the form.

Please guide me if i'm wrong.

Thanks in advt.
HBK
Posted

 
Share this answer
 
Please tell, which database you are using?
 
Share this answer
 
Comments
Harshad-HBK 11-Oct-11 6:52am    
I am using MS SQL Server 2005 as a back end database.
Syed Ammar Haider 12-Oct-11 6:05am    
Look man, as you say,
"I have used dataset , bindingsource and dataadapter on the form."

These APIs do not keep track of what is happening in the dataGridView. These are just used to retrieve data. If you want to save data after editing the dataGridView, you have to write the logic manually by yourself. For this please see the events associated with dataGridView.

OR

My suggestion in this regard is to leave the old ADO .Net(technology you are using) and try the new Entity Framework. This can perform automatic updates at the back end database keeping all the changes in the context.

For this, try this link:

http://www.codeproject.com/KB/database/IntroEntityFramework3.aspx

Hope this will help, Good Luck!
Look man, as you say,
"I have used dataset , bindingsource and dataadapter on the form."

These APIs do not keep track of what is happening in the dataGridView. These are just used to retrieve data. If you want to save data after editing the dataGridView, you have to write the logic manually by yourself. For this please see the events associated with dataGridView.

OR

My suggestion in this regard is to leave the old ADO .Net(technology you are using) and try the new Entity Framework. This can perform automatic updates at the back end database keeping all the changes in the context.

For this, try this link:

http://www.codeproject.com/KB/database/IntroEntityFramework3.aspx

Hope this will help, Good Luck!
 
Share this answer
 
If You use dataSet then see whether it have query for update or not in table adapter.
Now take a button on which click the data will be saved in database.
on this button click event use
C#
private void button2_Click(object sender, EventArgs e)
       {
           try
           {
               yourTableAdapter.Update(yourDataSet.tablename);
               MessageBox.Show("Record Updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           catch (Exception ex)
           {
               MessageBox.Show("Some Error in Update", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }

       }

Note:This code is in C#.
 
Share this answer
 
v2

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