How to DataAdapter Delete Command - SQL SERVER
SqlDataAdapter is a part of the ADO.NET Data Provider. The DataAdapter uses the Connection object of the .NET Framework data provider to connect to a data source and Command objects to retrieve data from and resolve changes to the data source.
InsertCommand , UpdateCommand , and DeleteCommand properties of the DataAdapter are Command objects that manage updates to the data in the data source according to modifications made to the data in the DataSet. The following C# code samples demonstrate how to use the SqlDataAdapter Object to Delete data from SQL Server database using DeleteCommand properties in SqlDataAdapter.
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
string connetionString = null;
SqlConnection connection ;
SqlDataAdapter adapter = new SqlDataAdapter();
string sql = null;
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
connection = new SqlConnection(connetionString);
sql = "delete product where Product_name ='Product6'";
adapter.DeleteCommand = connection.CreateCommand();
adapter.DeleteCommand.CommandText = sql;
MessageBox.Show ("Row(s) deleted !! ");
catch (Exception ex)