Execute.nonquery is giving the error of must declare the scalar variable.. please tell me solution
private void btndelete_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
string query = "delete stu_data where Reg_no=@regNo";
SqlDataAdapter sda = new SqlDataAdapter(query,con);
sda.SelectCommand.Parameters.AddWithValue("@regNo", textBox1.Text.ToString());
sda.DeleteCommand = con.CreateCommand();
sda.DeleteCommand.CommandText = query;
sda.DeleteCommand.ExecuteNonQuery();
}
}
}
Here you have a nice delete example:
Or if you are using SqlDataAdapter: