Click here to Skip to main content
11,435,451 members (59,684 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
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 18:40pm
Sam Path1.7K
Comments
Menon Santosh at 8-Nov-11 0:05am
   
Sampath U can find these solution in Ur text book :)
Rate this: bad
good
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)
        {
            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);
            }
 
        }
 
  Permalink  
Comments
Sam Path at 8-Nov-11 0:14am
   
How can i define the tablename....
in the line
yourTableAdapter.Update(yourDataSet.tablename);
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.
otherwise
set table of dataset as
myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet,"tablename");
Sam Path at 8-Nov-11 4:05am
   
Thank you got it :)
Rate this: bad
good
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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

  Permalink  
v2

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



Advertise | Privacy | Mobile
Web01 | 2.8.150428.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