I do not see in your code where you define the update and delete commands for the sql data adapter
You can use the SQLCommandBuilder class to create the update and delete commands. Of course you could also do it yourself
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Why does the SQL Command not Delete the Data from the Database, in the properties i have already set the sql command text on the Delete Comand. Is the sql Command used rightly?
public Form1()
{
InitializeComponent();
sqlConnection1.Open();
}
private void recreateXML_Click(object sender, EventArgs e)
{
dataSet11.Clear();
sqlDataAdapter1.Update(dataSet11);
String filePath = "";
openFileDialog1.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog1.FileName;
dataSet11.ReadXml(filePath);
sqlCommand1.ExecuteNonQuery();
sqlDataAdapter1.Update(dataSet11);
}
}
private void updateButton_Click(object sender, EventArgs e)
{
sqlDataAdapter1.Update(dataSet11);
}
private void deleteButton_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in dataGridView1.SelectedRows)
{
dataGridView1.Rows.Remove(row);
}
sqlDataAdapter1.Update(dataSet11);
}
}
}
I do not see in your code where you define the update and delete commands for the sql data adapter
You can use the SQLCommandBuilder class to create the update and delete commands. Of course you could also do it yourself
You are deleting the records in the DataGridView but not the DataSet bound to it. It has been a very long time since I have used a SqlDataAdapter but you need to use the command in the SqlDataAdapter.DeleteCommand Property.