Hello everyone!
I"m developing an application in Microsoft Visual C# 2010.
I"m have a listview where I display the record from database. I want to delete a selected record from listview and of course the same row from database. I found the solution for the first objective but not for the second.
The delete queries don"t want to execute, i can"t figure why!
Oh, and one more thing, I have an error when i want to acces the subitems of the listview, the error sounds like this "invalid argument 0", although i made a test in a Messabox button and gives me the right values of the items.
Please help!
Here is my code:
connect.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Cercetarestiintifica.mdf;Integrated Security=True;User Instance=True";
connect.Open();
foreach (ListViewItem eachItem in lv_profcarte.SelectedItems)
{
lv_profcarte.Items.Remove(eachItem);
}
string cmd1=@"DELETE FROM Profesor WHERE (marca = '"+lv_profcarte.SelectedItems[0].SubItems[3].Text+"')";
string cmd3=@"DELETE FROM Carte WHERE (ISBN = '"+lv_profcarte.SelectedItems[0].SubItems[8].Text+"')";
SqlCommand cmd2 = new SqlCommand(cmd1, connect);
SqlCommand cmd4 = new SqlCommand(cmd3, connect);
cmd2.ExecuteNonQuery();
cmd4.ExecuteNonQuery();
connect.Close();