我在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();
}
該代碼不會添加條目而不是刪除它。你的問題在別處。請張貼與此方法交匯的任何相關位。 –