I get this error:
Input string was not in a correct format.
from my code shown below. I want to delete a row in my database just with click on a button.
SqlConnection conn = new SqlConnection(@"DataSource=.\SQLEXPRESS;
AttachDbFilename=C:\Users\Mr\Documents\Student.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand();
int x = Convert.ToInt32(table2DataGridView.SelectedCells[0].Value);
cmd.Parameters.Clear();
cmd.Connection = con;
cmd.CommandText = "delete from Table2 where name=@N";
cmd.Parameters.AddWithValue("@N", x);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Removed");
I get the error on the first line.
@N
is my first textbox that I can put name on that.