I've got a local db in Visual Studio and in my project I want to delete a row which is selected in the WPF.
This is what I've got so far:
private void Delete(object sender, RoutedEventArgs e)
{
DataRowView o = (DataRowView)g2.SelectedItem;
int ID = Convert.ToInt32(o.Row.ItemArray[0]);
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=MYFOLDER";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("DELETE FROM [STOCK] WHERE o = @ID", con);
cmd.Connection = con;
cmd.ExecuteNonQuery();
{
MessageBox.Show("Row deleted");
}
In this statement I can select a row:
DataRowView o = (DataRowView)g2.SelectedItem;
int ID = Convert.ToInt32(o.Row.ItemArray[0]);
But then I have to delete it from my local db and I don't know how to complete this. I know this statement is wrong...but what is the right one:
cmd = new SqlCommand("DELETE FROM [STOCK] WHERE o = @ID", con);
Hope anybody can help me. I'm using Visual Studio 2019 - it's a WPF project with C#.