在ADO中 
strSQL = "select * from t1 where c1=" & aaa 
这里aaa是个string类型的变量名 为什么这样写不行?
书上的写法是 
    strSQL = "SELECT * FROM t1 WHERE C1 = " & Chr(34) & aaa & Chr(34)
为什么要这样写,还有其他方便些的写法吗

解决方案 »

  1.   

    字符串要写在里边"select  * from  t1  where  c1='"& 变量 &"'"
      

  2.   

    chr(34)是"号
    在sql中字符串一般要用括号括起来,不过一般应该是用单括号吧例如:select * from youtable where name='lsf';
      

  3.   

    strSQL = "select  * from  t1  where  c1= '"+ 变量 +"' "
      

  4.   

    strSQL = "select * from t1 where c1=" & aaa 
    改成:
    strSQL = "select * from t1 where c1='" & aaa & "'"
      

  5.   

    '数值类型的变量引用:strsql="select * from t1 where c1="& aaa &""
    '字符类型的变量引用:strsql="select * from t1 where c1='"& aaa &"'"
    '日期类型的变量引用:strsql="select * from t1 where c1='"& aaa &"'"  (SQL)
                         strsql="select * from t1 where c1=# " & aaa & "#" (ACCESS)