I have Datagridview1 which is bound to dataset1 via bindingsource. I want to be able to add new rows, edit them and also delete them during runtime with the help of control buttons (Add, Edit, Delete).

How can this be done

Re: Windows Forms Data Controls and Databinding Adding, editing, deleting new rows in a Databound Datagridview

Gavin Jin - MSFT


Hi,please check this thread PostID=109453&SiteID=1

Implementing a Delete, Insert and Update operations you must have a DataAdapter and define its Delete, Insert and Update commands. You could use this adapter against your datasource and call the adapters' update method...

SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM table1", conn);
adapter.InsertCommand = new SqlCommand("INSERT INTO table1 VALUES(@param1, @param2)", conn);

Just do the same to the Update and Delete commands. Then, Create a DataSet and Fill it using the adapter and make it as a datasource of your datagrid...

DataSet ds = new DataSet();
DataGrid1.DataSource = ds;

When you want to send your changes to the database you can just call the adapter.update method...