C#中的查询语句

来源:百度知道 编辑:UC知道 时间:2024/06/20 06:09:43
switch (cboType.Text)
{

case "序号":

strSql_myselect = strSql_myselect + " where Id =" + txtContent.Text;
break;

case "姓名":
strSql_myselect = strSql_myselect + " where Name =' " + txtContent.Text + " ' ";
break;

case "性别":
strSql_myselect = strSql_myselect + " where Sex ='" + txtContent.Text + "'";
break;

case "身份证":
strSql_myselect = strSql_myselect + " where IdCardNo ='" + txtContent.Text + "'";
break;

case "等级":
strSql_myselect = strSql_myselect +

SQL Server里面'(单引号)是用于varchar的
而C#里面"双引号是用于String的

拼出来最后执行的时候其实就是
strSql_myselect = strSql_myselect + " where Grade ='value'";

这是多重条件语句嵌套的结果,当语句嵌套的时候,必须使用不同的引号将一个条件括起来才可以

字符串的连接啊
strSql_myselect 和 txtContent.Text 本身是变量字符串类型 不用加引号
where Grade=''是条件等于空 是一个字符串 要加引号 就是本身 用引号

双引号表示是字符串之间的连接,单引号是sql语句中当用到查询条件是字符串或者插入数据是字符串时就要用单引号把它括起来。
strSql_myselect = strSql_myselect + " where Grade ='" + txtContent.Text + "'"这句要是正常显示的话应该是strSql_myselect = strSql_myselect where Grade ='文本框中的数据'