我想看看是否記錄表中存在它之前,我寫一個文件,但我不斷收到一個錯誤如何查找數據庫記錄是否存在?
string InformationCheck = "Select FName,LName from Customer where FName ='" + this.f_Name.Text + "' and LName = '" + l_Name.Text + "'";
OleDbCommand InfoCheck = new OleDbCommand(InformationCheck, conn);
String strResult = String.Empty;
try
{
conn.Open();
strResult = (String)InfoCheck.ExecuteScalar();
if (strResult.Length == 0)
{
MessageBox.Show("Dose Not Exist");
AddInfo.ExecuteReader();
conn.Close();
this.Hide();
f1.Show();
}
else
{
MessageBox.Show("Exists");
}
}
catch (Exception ex)
{
MessageBox.Show("" + ex + "");
}
你能分享錯誤訊息嗎? – WLin
你在做(字符串)ExecuteScalar()但要求返回2個項目。 – Jonesopolis
直到您指定錯誤消息:FName的結尾單引號和「和」關鍵字之間是否有空格?在上面的文字中很難說。 – JTMon