我有一個文本框,它將從用戶接收輸入並搜索插入的數據是否在SQL數據庫表中可用。如果數據在表中,那麼它將更新同一行的兩列(time_out和day_out)。
否則它會顯示一條錯誤消息。以下代碼無法使用。請幫忙。從文本框中檢查數據庫數據
try
{
SqlConnection con3 = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True");
con3.Open();
SqlCommand cmd2 = new SqlCommand(@"SELECT Count(*) FROM Visitors WHERE [email protected]",con3);
cmd2.Parameters.AddWithValue("@id", textBox_VIex.Text);
SqlCommand cmd3 = new SqlCommand("UPDATE Visitors SET [email protected],[email protected] WHERE [email protected]", con3);
cmd3.Parameters.AddWithValue("@id", 1);
cmd3.Parameters.AddWithValue("@dO", DateTime.Now);
cmd3.Parameters.AddWithValue("@tO", DateTime.Now);
int o = cmd3.ExecuteNonQuery();
MessageBox.Show("Good Bye!");
this.Close();
FormCheck f2 = new FormCheck();
f2.Show();
}
catch
{
MessageBox.Show("Error!");
textBox_VIex.Clear();
}
那麼,問題究竟是什麼? – OldProgrammer
我可以看到一個問題cmd3.Parameters.AddWithValue(「@ id」,1),爲什麼你總是傳遞1? – Devesh
當你說某事不行時,你需要指定發生的事情。你有錯誤嗎?如果你得到一個異常,請添加堆棧跟蹤,所以我們可以幫助你:) – Dzyann