我很难从 SQL 数据库中删除一行,我没有收到任何错误,而且它似乎工作正常,但没有删除任何内容。当我运行代码时,它将输出“名称已被删除”
谢谢你的帮助。
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\MyDB.mdf;Integrated Security=True";
try
{
conn.Open();
SqlCommand Command = conn.CreateCommand();
Command.CommandText = "DELETE FROM Contacts WHERE [First Name] = '@Name';";
Command.Parameters.AddWithValue("@Name", DropDownList1.SelectedValue);
Command.ExecuteNonQuery();
TextBox1.Text = DropDownList1.SelectedValue + " Has Been Deleted";
}
catch (Exception ex)
{
TextBox1.Text = "Nope";
}
finally
{
conn.Close();
}