数据类型不匹配
问题描述:
我在数据库表中的数据类型是短文本,我不知道为什么,我在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();
答
如果ID是自动编号,那么您不需要引号。试试这个:
command2.CommandText = "UPDATE CheckIn_Details SET ModeOfCheckIn='True'
WHERE ID=" + id;
'ModeOfCheckIn'&'ID'的数据类型是什么?错误很明显:第二个查询中使用的数据类型不匹配。 –
对方说ModeOfCheckIn是短文本,ID是自动编号 –