我必须从字符串值构建查询字符串,例如:
connString += "INSERT INTO (...) VALUES ( "+
_cd.userName "," +
//and there i'd like to use ?: operators:
_cd.lastLogin == "Null" ? "null" : _cd.lastLogin ","
所以我的查询看起来像INSERT INTO (...) VALUES ('name', null, (...))
但是当我使用它时,它会切断我的字符串,所以它看起来像
",null,1,2,'name', (...)";
好吧,我知道我可以使用 var a,b,c,d 然后检查是否(_cd.lastLogin == "Null) a = null
并将其放入字符串中,但是有很多变量。
什么是正确的使用方法?
@编辑:代码:
string query = "INSERT INTO PersonLogin(...) " + Environment.NewLine +
"VALUES (" + _cD.userID + ","
+ "'" + _cD.number + "',"
+ "'" + _cD.dateCreate + "','"
+ _cD.lastLogin == "Null" ? ",null," : _cD.lastLogin + "',"
+ _cD.taken + ","
+ _cD.canLogin + ""+ Environment.NewLine;