我是用dao来访问数据库的,下面是我的一段代码:
Dim TableName As String
Dim tantouhao As String
Dim database As dao.database
Dim rs As dao.Recordset
dbname = Month(dat) & "0" & Day(dat) & ".mdb"
TableName="1"
tantouhao="101"
Set database = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\" & Year(Now) & "\" + dbname)
Set rs = database.OpenRecordset("select * from " & TableName & " where 分站号=" & tantouhao)
出现了问题,系统提示说:too few parameters expected 1.
究竟是OpenRecordset语句中哪里出了错,请指教。

解决方案 »

  1.   

    Set rs = database.OpenRecordset("select * from " & TableName & " where 分站号=" & tantouhao)
    如果是字符类型,应该要单引号的
      

  2.   

    OpenRecordset("select * from " & TableName & " where 分站号=" & tantouhao)
    是不是还有需要一些参数?
      

  3.   

    我调试过,上语句改成这样就可以:
        Set rs = database.OpenRecordset("select * from " & TableName )
    加了之后就不行,系统提示说参数少,但上句就可以,怎回事呢?
        同时我提示:tantouhao是整型类型。
        在线等!!!!!
      

  4.   

    在上述程序代码中,tantouhao是string,是我为了调试才改的,(原为integer)
      

  5.   

    “分站号”的数据类型是什么??如果是字符型,语句就要改为Set rs = database.OpenRecordset("select * from " & TableName & " where 分站号='" & tantouhao & "'")