现有两个表 业务经验 和 社员信息 两个表一一对应关系 两表就主码:社员代码 相同
检索条件:两个表里的条件都有 要求在datagrid1里显示检索结果
以下是我写的一段代码(检索条件分别写了几个表示一下)
运行显示的错误为:res2.Open sql, cn, adOpenStatic, adLockOptimistic 有问题
就是sql = "select 社员代码,性别,年龄 from 社员信息 where 社员代码 in res1.Recordset "有问题
请高手给看看错在哪?
Private Sub Command2_Click()
Dim sql1 As String
Dim sql As String
Dim conn As ADODB.Connection
Dim cn As ADODB.Connection
Dim res1 As ADODB.Recordset
Dim res2 As ADODB.Recordset
Set conn = New ADODB.Connection
Set res1 = New ADODB.Recordset
sql1 = "select 社员代码 from 业务经验 where 社员代码 like '%'"
If Text1.Text <> "" Then
sql1 = sql1 + " and OS like '" + Combo3.Text + "%' "
End If
If Text1.Text <> "" Then
sql1 = sql1 + " and DB like '" + Combo3.Text + "%' "
End If
If Text2.Text <> "" Then
sql1 = sql1 + "and 工作年限 like '" + Combo7.Text + "%'"
End If
If Combo1.Text <> "" Then
sql1 = sql1 + "and 语言 like '" + DataCombo3.Text + "%' "
End If
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
res1.CursorLocation = adUseClient
res1.Open sql1, conn, adOpenStatic, adLockOptimistic
Set cn = New ADODB.Connection
Set res2 = New ADODB.Recordset
sql = "select 社员代码,性别,年龄 from 社员信息 where 社员代码 in res1.Recordset "
If Text1.Text <> "" Then
sql = sql + " and 社员代码 like '" + Text1.Text + "%' "
End If
If Text2.Text <> "" Then
sql = sql + "and 性别 like '" + Text2.Text + "%'"
End If
If Combo1.Text <> "" Then
sql = sql + "and 年龄 like '" + Combo1.Text + "%' "
End If
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db2.mdb;Persist Security Info=False"
res2.CursorLocation = adUseClient
res2.Open sql, cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = res2
MsgBox "检索成功", vbOKOnly + vbExclamation
sql = ""
DataGrid1.Refresh
DataGrid1.Refresh