string strUserName = "张宇";sqlwhere="where UserType = 1 and username= "" + strUserName  +"""  这种做法是错的要得到字符串 where UserType = 1 and username= "张宇" ,该如何表示?
另外 '' 与  "" 有什么不同?

解决方案 »

  1.   

    where UserType = 1 and username= '" + strUserName  +"'"
      

  2.   

    上面写的对
    你那个写法出来的结果是where UserType = 1 and username= 张宇
    只需要把'当做字符串写在里面就成。
    SQL里'中间的表示字符串
      

  3.   

    C#和html中有转义字符吗?
    类似pb中的~,delphi中的\
      

  4.   

    zykj_2000的写法是对的,但这样写容易遭到黑客的攻击。安全的写法是使用参数。具体写法请参照.netsdk快速入门。microsoft所有的数据库操作代码都是用参数写的。
      

  5.   

    C#中的\就是转义字符,如:
    string s = "He said: \"Hello, world!\"\r\n";
      

  6.   

    在SQL中字符串是用单引号,而不是双引号:
    where UserType = 1 and username= '张宇'