c#中的SQL选择语句

本文关键字:语句 选择 SQL 中的 | 更新日期: 2023-09-27 18:06:05

我在执行以下代码时遇到问题(语法错误)。请告诉我该怎么办。谢谢。

表列:pId, pAltId, pMobile, pDate, pName

变量:argID, alt_ID, p_mobile, p_date, p_Name

声明:

String selectStr = "select * from " + thisTable + " where pId = '" + argID "+  OR  + 
pAltId = " + alt_ID "+ OR + pMobile =" + p_mobile "+ OR +  pDate =" + p_date "+ OR + 
pName = "+ p_Name "'";

c#中的SQL选择语句

+ " where pId = '" + argID "+中,pId的值是否应在单引号中?你有开始,但没有结束。

你似乎也缺少了一些双引号,或者把它们放在了错误的地方,缺少了一些空格,并且缺少了pName的起始'。试一试:

String selectStr = "select * from " + thisTable + " where pId = " + argID + " " 
    + OR + " pAltId = " + alt_ID + " " + OR + " pMobile = " + p_mobile + " " 
    + OR + " pDate = '" + p_date + "' " + OR + " pName = '" + p_Name + "'";

如果pMobile是字符串,则需要将+ " pMobile = " + p_mobile + " "更改为+ " pMobile = '" + p_mobile + "' "