我在打开一个表的时候,所订的条件为一个变量,我的语法并不错,为休老地提示出错。
strSQL="select * from 测试结果 where 索引 = '"combo1.listIndex"'"
myRS.Open strSQL, adOpenKeyset, adOptimitic, adCmdTable
请高手指点.

解决方案 »

  1.   

    strSQL="select * from 测试结果 where 索引 = '" & combo1.listIndex & "'"
      

  2.   

    当然有错了
    combo1.listIndex为一数字值变量strSQL="select * from 测试结果 where 索引 = '"combo1.listIndex"'"
    但你在这一句时加入了引号,而且在连接时没有用到 "&" 或 "+" 这个连接字符串的语法
    正确的应该是:
    strSQL="select * from 测试结果 where 索引 = " & combo1.listIndex 
      

  3.   

    strSQL="select * from 测试结果 where 索引 = '" & combo1.listIndex & "'"
    or
    strSQL="select * from 测试结果 where 索引 = '" & combo1.text & "'"
    or
    strSQL="select * from 测试结果 where 索引 = " & combo1.listIndex 
      

  4.   

    strSQL="select * from 测试结果 where 索引 = '"combo1.listIndex"'"
    myRS.Open strSQL, adOpenKeyset, adOptimitic, adCmdTable
    你认为对吗?myRS.Open strSQL, adOpenKeyset, adOptimitic, adCmdTable
    这句里面连CONNECTIONSTRING都没有怎么可能对呢?dim conn as new adodb.connection
    conn.open connectionstringstrSQL="select * from 测试结果 where 索引 = '"combo1.listIndex"'"
    myRS.Open strSQL,conn, adOpenKeyset, adOptimitic, adCmdTable这样就应该没有问题了~~
      

  5.   

    差点漏了,
    strSQL="select * from 测试结果 where 索引 = '"combo1.listIndex"'"
    myRS.Open strSQL, adOpenKeyset, adOptimitic, adCmdTable要改为strSQL="select * from 测试结果 where 索引 = '" & combo1.listIndex & "'"
    myRS.Open strSQL,conn, adOpenKeyset, adOptimitic, adCmdTable
      

  6.   

    在调试器上看看你的strSQL应该就能明白了。
      

  7.   

    如果索引是数值型字段
    strSQL="select * from 测试结果 where 索引 = " & combo1.listIndex
    myRS.Open strSQL, adOpenKeyset, adOptimitic, adCmdTable
      

  8.   

    strSQL = "select * from  测试结果 where 索引 = '" + combo1.listIndex + "'"......
      

  9.   

    str="select * from 测试结果 where 索引 =" & str(combo1.listindex)
    myRS.Open strSQL,conn, adOpenKeyset, adOptimitic, adCmdTable
      

  10.   

    索引的类型是Integer,我做过多次:如
    strSQL="select * from 测试结果 where 索引 =" & str(combo1.listindex)
    myRS.Open strSQL,conn, adOpenKeyset, adOptimitic, adCmdTablestrSQL="select * from 测试结果 where 索引 ="'"& str(combo1.listindex) & "'"
    myRS.Open strSQL,conn, adOpenKeyset, adOptimitic, adCmdTable
    程序总是提示错误,当我把strSQL更换为表的时候就正常了。但是我无法设置条件查询。我只能设为:
    myrs.MoveFirst
    While not myrs.Eof
    wd=myrs("索引")
    wt=myrs("放大倍数")
    If wd=listIndex then
    myNeedWt=myrs("放大倍数")
    exit sub
    end if
    myrs.MovrNext
    Wend
    这样就能找到我所要的值,只是麻烦一点,我一直不明白我的SQL查询为何会出错?