我在SQL中遇到了一个简单的DELETE语句出现意外结果的麻烦,它似乎将这个单词添加到列表中。必须是愚蠢的东西!但我看不到它,尝试了几种不同的方法。所有相同的结果如此混乱。SQL删除命令?
public void IncludeWord(string word)
{
// Add selected word to exclude list
SqlConnection conn = new SqlConnection();
String ConnectionString = "Data Source = dev\\SQLEXPRESS ;" + "Initial Catalog=sml;" + "User id=** ;" + "Password =*;" + "Trusted_Connection=No";
using (SqlConnection sc = new SqlConnection(ConnectionString))
{
try
{
sc.Open();
SqlCommand Command = new SqlCommand(
"DELETE FROM excludes WHERE word='@word'" +
conn);
Command.Parameters.AddWithValue("@word", word);
Command.ExecuteNonQuery();
}
catch (Exception e)
{
Box.Text = "SQL error" + e;
}
finally
{
sc.Close();
}
ExcludeTxtbox.Text = "";
Box.Text = " Word : " + word + " has been removed from the Exclude List";
ExcludeLstBox.AppendDataBoundItems = false;
ExcludeLstBox.DataBind();
}
该代码不会添加条目而不是删除它。你的问题在别处。请张贴与此方法交汇的任何相关位。 –