Update table in database through datagridview in winform
Please help me in solving following query:
I want to update table at backend in database throughmakeing changes in datagridview.
What I want is, when User makes changes in datagridview and clicks save or update button, the changes which are made in datagridview should get reflect in table in databse.
I am having "Datagridview", "Edit" and "Save" button on WinForm and table "EmpDetails" at backend in databse. I am filling "Datagridview" with table "EmpDetails". When user clicked "Edit" button he should allowed to make changes in "Datagridview". After making changes in "Datagridview" when user clicked "Save" button, whichever changes made in datagridview should get reflect at backend in table "EmpDetails".
Use this code to populate datagridview
SqlDataAdapter da=new SqlDataAdapter("select * from product",strcon);
SqlCommandBuilder cb=new SqlCommandBuilder(da);
DataSet ds = new DataSet();
//now u can save changes to back end with
In case of joins in dataset what is the solution
It is working fine if there is single table in dataset.
But in my dataset there are 4 table with join (i.e. to fill datagrid I am combining data from 4 tables by using joins). So what should I do in this case?
Thanks & regards,
Hi. I'm working with that right now. I'm new to this so there may be a better solution than this:
Make a DataAdapter for each Table (ie. Customers and Orders).
For filling the dataset:
For updating the Database:
If your DataSet or your Database enforce some Relations you have to call the Fill and Update methods accordingly.
I also had the problem of errors occuring when i altered the primary key of a line in the dataset. That can be solved by making the primaryKey column uneditable.
Comments on this post
February 24th, 2014, 08:06 PM
Originally Posted by handshakeit
Thanks it works!