求助:拼接SQL字符串的问题
用字符串拼接的SQL语句,比如:
"insert into table1 (UnitPrice,SumPrice) values("+UnitPrice+","+SumPrice+")"
UnitPrice,SumPrice是数值类型的变量,如果值为null,拼接时就会变成空字符串:
"insert into table1 UnitPrice,SumPrice values(,)"
这就导致语法错误,请问这该怎么处理?
------解决方案--------------------
string sql ="insert into table1 (UnitPrice,SumPrice) values("+UnitPrice??0+","+SumPrice??0+")";
------解决方案--------------------string sql =string.Fromat("insert into table1 (UnitPrice,SumPrice) values('{0}','{1}')",UnitPrice??0,SumPrice??0);