Click here to Skip to main content
11,647,170 members (65,829 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
How to Edit and Update in the DataGridview in winform app using c# .
If click Update it is Changed in the database also...
Posted 7-Nov-11 17:40pm
Sam Path1.7K
Menon Santosh at 8-Nov-11 0:05am
Sampath U can find these solution in Ur text book :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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

private void button2_Click(object sender, EventArgs e)
                MessageBox.Show("Record Updated", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            catch (Exception ex)
                MessageBox.Show("Some Error in Update", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
Sam Path at 8-Nov-11 0:14am
How can i define the tablename....
in the line
Uma Shankar Patel at 8-Nov-11 0:33am
are you bind your datagridview by coding or Wizard.
Sam Path at 8-Nov-11 0:45am
by coding...
Uma Shankar Patel at 8-Nov-11 1:59am
when you will create it from wizard, table adapter and queries for table adapter are auto generated.
I think it will be easy to do through wizard.
set table of dataset as
myDataSet = new DataSet();
Sam Path at 8-Nov-11 4:05am
Thank you got it :)
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Dataset is the main part in all your operations.

1. Fetch the values in dataset from database.
2. Bind it with gridview. Put gridview editable (so user edit values whatever
they want)
3. after editing put gridview table to dataaset.
4. finally update dataset to database.

Gridview changes to dataset.

DataTable dt = (DataTable)GridView1.DataSource; 
 Dataset ds = new dataSet;
 ds.tables[0] =  dt 

and then Save Dataset Changes to a Database[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 5


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

  Print Answers RSS
0 500
1 F-ES Sitecore 370
2 DamithSL 335
3 OriginalGriff 322
4 CPallini 290
0 OriginalGriff 1,277
1 994
2 DamithSL 946
3 Sergey Alexandrovich Kryukov 853
4 CPallini 760

Advertise | Privacy | Mobile
Web01 | 2.8.150804.2 | Last Updated 8 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100