我用这个语句检索数据库可是运行时出现如下错误,请各位大虾帮忙找找出错的地方(这里用到了两个表连接查询):
Private Sub Command1_Click()
Dim rst As New ADODB.Recordset
Dim sql As String
Dim s As String
s = Me.DTPicker1.Valuesql = "select * from 方案,施工项目 where 方案.来方案日期='" + s + "'" & "And 方案.本次施工队='' " & " And 方案.项目=施工项目.分类项目"rst.Open sql, cnn, adOpenStatic, adLockOptimistic
Set DR1.DataSource = rst
With DR1
.Sections.Item("section2").Controls.Item("label2").Caption = Format(Form1.DTPicker1.Value, "YYYY年MM月DD日")
.Sections.Item("section3").Controls.Item("label10").Caption = Format(Form1.DTPicker1.Value, "YYYY年MM月DD日")
.Sections(3).Controls("text1").DataField = "项目"
.Sections(3).Controls("text2").DataField = "矿别"
.Sections(3).Controls("text3").DataField = "井号" '+ "项目"
.Show
End With
End Sub

解决方案 »

  1.   

    是这的错
    sql="select * from 方案 a,施工项目 b "& _
        "where a.项目=b.分类项目 and a.来方案日期=#"& s &"# and a.本次施工队=''"给你个例子,你用的好不方便
    你试试吧,好用的
    记得要引用adoDim WithEvents adoPrimaryRS As Recordset '数据库连接对象
    Private Sub Command1_Click()
       'strsql 是你的查询语句 你可以order by 排序的字段
       'strsql="select xh as 学号 from 表" 这里的学号就是你数据表中字段的标题
       strsql="select 字段 from 表"
       Set Db = New Connection
       Db.CursorLocation = adUseClient
       '下面的连接数据字符串你要修改一下
       Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
       Set adoPrimaryRS = New Recordset
       adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic
       Set DataGrid1.DataSource = adoPrimaryRS
    end sub
      

  2.   

    sql = "select * from 方案,施工项目 where 方案.来方案日期=#" + s + "# " & "And 方案.本次施工队='' And 方案.项目=施工项目.分类项目"