2017-07-25 148 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;