我不得不從字符串值建立查詢字符串,如:字符串和? :運營商
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
並將其放入字符串中,但有很多變量。
什麼是正確的使用方法?
@EDIT: 代碼:
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;
對不起,我忘了 - C#。 – user13657
正確的方法是使用SqlParameters。像這樣構建你的查詢是瘋狂的。 – Arran
阿蘭說了些什麼。但是要回答你的問題,可能把括號用在''的所有用法上? :'。 – Jon