我的示例代码如下,我收到以下错误;
标准表达式中的数据类型不匹配错误。
详情=> ScannerAlarmLimits是来自.mdb数据库的表。
string jointS = dsetChamberS1.Tables[0].Rows[tot][0].ToString();
int select1S = Convert.ToInt32(jointS);
string sqlQuery1S = "SELECT TMin,TMax,HMin,HMax from ScannerAlarmLimits WHERE ScannerID='" +select1S+ "'";
OleDbCommand cmd1S = new OleDbCommand(sqlQuery1S, conn);
OleDbDataAdapter adapter1S = new OleDbDataAdapter(cmd1S);
adapter1S.Fill(dsetTempS, "ScannerAlarmLimits");
答案 0 :(得分:1)
如果您的ScannerID
列是整数,那么您不应该使用单引号。单引号用于字符。等;
WHERE ScannerID = " + select1S;
但作为更好的方法,您应该始终使用parameterized queries。这种字符串连接对SQL Injection攻击是开放的。阿卡bobby-tables。
并使用using
statement来处置您的连接,命令和适配器。
string jointS = dsetChamberS1.Tables[0].Rows[tot][0].ToString();
int select1S = Convert.ToInt32(jointS);
using(var conn = new OleDbConnection(conString))
using(var cmd1S = conn.CreateCommand())
{
cmd1S.CommandText = "SELECT TMin,TMax,HMin,HMax from ScannerAlarmLimits WHERE ScannerID = @id";
cmd1S.Parameters.AddWithValue("@id", OleDbType.Integer).Value = select1S;
using(var adapter1S = new OleDbDataAdapter(cmd1S))
{
adapter1S.Fill(dsetTempS, "ScannerAlarmLimits");
}
}
答案 1 :(得分:1)
我刚刚在where子句的条件下添加单引号,现在它正在工作。
var query = "SELECT * from checkinout where read <> '1'";