Click here to Skip to main content
15,904,934 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am having datagrid view in my form and now i want to insert, delete update data through datagrid view .I have created simple application for insert
code is as follows

C#
private void Form1_Load(object sender, EventArgs e)
       {
           
           com.Connection = con;

       }



C#
 private void button4_Click(object sender, EventArgs e)
        {
SqlConnection con=new SqlConnection("Data Source=C:\asd;Initial Catalog=shivani;  providerName=System.Data.SqlClient ");
        SqlCommand com = new SqlCommand();


if (txtname.Text != "" & txtage.Text != "")
           {
               con.Open();
               com.CommandText = "insert into customer(customerName,customerCode) values ('" + txtname.Text + "','" + txtage.Text + "')";
               com.ExecuteNonQuery();
               con.Close();
               MessageBox.Show("record inserted");
           }
           else MessageBox.Show("data entry error");
}



Now i want to do same thing through datagrid view...
so tell me how to do that

thanks in advance
Posted
Updated 1-Jan-13 3:19am
v2

1 solution

Bind the datagrid with the data adaptor and use it to push data to db.
There are multiple ways to achieve it. Few links to help you out:

http://www.codeguru.com/csharp/.net/net_data/datagrid/article.php/c13041/Add-Edit-and-Delete-in-DataGridView.htm[^]

http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/8db841fc-ffa7-4519-b6f5-d054c7190948[^]

Hope it helps..
 
Share this answer
 

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