甚至可以在沒有 " " 的情況下回傳字串的值嗎?
我有以下字串: Chb = "NOT";
現在,我不是要洗掉的“”在C#或SQL。
所以我想Chb = NOT在 C# 中使用,或者我想洗掉我在 @Chb 中獲得的 SQL中的“ ”,以便:
WHERE PAR @Chb IN ('1','2','3')
不是這樣的: WHERE PAR 'NOT' IN ('1','2','3')
但就是這樣 WHERE PAR NOT IN ('1','2','3')
uj5u.com熱心網友回復:
我不相信這是正確的方法。
如果您想在來自 C# 代碼的 SQL 中執行命令,那么我會這樣做:
string exists = "select * from table where var in (1,2,3)";
string notExists = "select * from table where var NOT in (1,2,3)";
if (chb != "NOT")
{
SqlCommand cmd = new SqlCommand(exists, con);
cmd.ExecuteScalar();
}
else
{
SqlCommand cmd = new SqlCommand(notExists, con);
cmd.ExecuteScalar();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/383541.html
上一篇:谷歌地圖內容安全政策錯誤
下一篇:如何從類中洗掉默認屬性值
