2017-07-25 255 views
0

我在數據庫表中的數據類型是短文本,我不知道爲什麼,我在command2.ExecuteNonQuery();數據類型不匹配

錯誤消息

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll收到此錯誤

Additional information: Data type mismatch in criteria expression.

我的代碼

OleDbCommand cmd1 = new OleDbCommand(); 
cmd1.Connection = con; 
cmd1.CommandText = "SELECT * FROM Customers Where [email protected] OR [email protected] OR [email protected]"; 
cmd1.Parameters.AddWithValue("@FirstName", txtSearch.Text); 
OleDbDataReader read2 = cmd1.ExecuteReader(); 
string id = ""; 
while(read2.Read()) 
{ 
    id = read2["id"].ToString(); 
} 
OleDbCommand command2 = new OleDbCommand(); 
command2.CommandText = "UPDATE CheckIn_Details SET ModeOfCheckIn='True' WHERE ID='" + id + "'"; 
command2.Connection = con; 
command2.ExecuteNonQuery(); 
+0

'ModeOfCheckIn'&'ID'的數據類型是什麼?錯誤很明顯:第二個查詢中使用的數據類型不匹配。 –

+0

對方說ModeOfCheckIn是短文本,ID是自動編號 –

回答

0

如果ID是自動編號,那麼您不需要引號。試試這個:

command2.CommandText = "UPDATE CheckIn_Details SET ModeOfCheckIn='True' 
WHERE ID=" + id;