同一组数据,用参数化查询,返回错误0,拼接字符串,返回正确值1。不知何故?
参数化查询
public bool IsMeetRzlx2(string rzlx, string item, string wlbm, string gysh)
{
string sql = @"SELECT COUNT(0) FROM ssaln.ttcibd924400 b
WHERE b.t$suno=:v_gysh
AND b.t$item=:v_item
AND b.t$rzlx=:v_rzlx
AND b.t$mitm=:v_mitm";
OracleParameter[] _param = {
new OracleParameter("v_gysh", gysh),
new OracleParameter("v_item", wlbm),
new OracleParameter("v_rzlx", rzlx),
new OracleParameter("v_mitm", item)
};
OracleConnection conn = new OracleConnection("…");
OracleCommand cmd= new OracleCommand(sql, conn);
cmd.Parameters.AddRange(_param);
conn.Open();
object obj = cmd.ExecuteScalar();
conn.Close();
return (obj != DBNull.Value && Convert.ToInt32(obj) > 0) ? true : false;
}
{
string sql = @"SELECT COUNT(0) FROM ssaln.ttcibd924400 b
WHERE b.t$suno=:v_gysh
AND b.t$item=:v_item
AND b.t$rzlx=:v_rzlx
AND b.t$mitm=:v_mitm";
OracleParameter[] _param = {
new OracleParameter("v_gysh", gysh),
new OracleParameter("v_item", wlbm),
new OracleParameter("v_rzlx", rzlx),
new OracleParameter("v_mitm", item)
};
OracleConnection conn = new OracleConnection("…");
OracleCommand cmd= new OracleCommand(sql, conn);
cmd.Parameters.AddRange(_param);
conn.Open();
object obj = cmd.ExecuteScalar();
conn.Close();
return (obj != DBNull.Value && Convert.ToInt32(obj) > 0) ? true : false;
}
拼接字符串
public bool IsMeetRzlx2(string rzlx, string item, string wlbm, string gysh)
{
string sql = "SELECT COUNT(0) FROM ssaln.ttcibd924400 b "
+ "WHERE b.t$suno='" + gysh + "' "
+ "AND b.t$item='" + wlbm + "' "
+ "AND b.t$rzlx='" + rzlx + "' "
+ "AND b.t$mitm='" + item + "'";
OracleConnection conn = new OracleConnection("…");
OracleCommand cmd= new OracleCommand(sql, conn);
conn.Open();
object obj = cmd.ExecuteScalar();
conn.Close();
return (obj != DBNull.Value && Convert.ToInt32(obj) > 0) ? true : false;
}
{
string sql = "SELECT COUNT(0) FROM ssaln.ttcibd924400 b "
+ "WHERE b.t$suno='" + gysh + "' "
+ "AND b.t$item='" + wlbm + "' "
+ "AND b.t$rzlx='" + rzlx + "' "
+ "AND b.t$mitm='" + item + "'";
OracleConnection conn = new OracleConnection("…");
OracleCommand cmd= new OracleCommand(sql, conn);
conn.Open();
object obj = cmd.ExecuteScalar();
conn.Close();
return (obj != DBNull.Value && Convert.ToInt32(obj) > 0) ? true : false;
}