编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
 
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

求助关于数据库的问题

求助关于数据库的问题

请教一下,代码错在什么地方。运行之后的提示错误是  “未找到方法或数据成员”
'str定义在通用里
Private Sub Command2_Click()
Dim a, i As Integer
str = Combo1.Text
For i = 0 To 3
If Option1(i).Value = True Then
a = i
End If
Next i
Select Case a
Case 0
DataGrid1.DataSource = Adodc1(1)
DataGrid1.Refresh
Case 1
DataGrid1.DataSource = Adodc1(2)
DataGrid1.Refresh
Case 2
DataGrid1.DataSource = Adodc1(3)
DataGrid1.Refresh
Case 3
DataGrid1.DataSource = Adodc1(4)
DataGrid1.Refresh
End Select
End Sub

Private Sub Form_Load()
'Adodc1(0)的RecordSource属性先定义了
Adodc1(1).RecordSource = "select * from 加班 where 职工号='&str&'"
Adodc1(2).RecordSource = "select * from 请假 where 职工号='&str&'"
Adodc1(3).RecordSource = "select * from 考勤统计 where 职工号='&str&'"
Adodc1(4).RecordSource = "select * from 出差 where 职工号='&str&'"
End Sub

TOP

Adodc1(index).ConnectionString属性有赋值吗?

TOP

赋值了,在属性里赋值的

TOP

现在稍微改了一下,运行没有错误了,但是。。。问题又出来了,选择查询过后能显示表头,但显示不出选择的职工号的信息,我郁闷,不太懂这个东西,找不到问题所在,请高手指点一下,急用,谢谢啦!
Dim str As String
Dim rs As ADODB.Recordset
Dim conn As ADODB.Connection



Private Sub Command1_Click()
考勤记录.Show
Unload 按职工号查询
End Sub

Private Sub Command2_Click()
Dim i As Integer
str = Combo1.Text
Adodc1(1).RecordSource = "select * from 加班 where 职工号='&str&'"
Adodc1(2).RecordSource = "select * from 请假 where 职工号='&str&'"
Adodc1(3).RecordSource = "select * from 考勤统计 where 职工号='&str&'"
Adodc1(4).RecordSource = "select * from 出差 where 职工号='&str&'"
If Option1(0).Value = False And Option1(1).Value = False And Option1(2).Value = False And Option1(3).Value = False Then
   MsgBox ("请先选择查询项目再查询!")
End If

For i = 0 To 3
If Option1(i).Value = True Then
  Set DataGrid1.DataSource = Adodc1(i + 1)
  DataGrid1.Refresh
End If
Next i
End Sub

Private Sub Form_Load()
Adodc1(0).Visible = False
Adodc1(1).Visible = False
Adodc1(2).Visible = False
Adodc1(3).Visible = False
Adodc1(4).Visible = False
Set conn = New ADODB.Connection
conn.Open "mydata"
Set rs = New ADODB.Recordset
rs.Open "select * from 职工", conn, adOpenDynamic, adLockOptimistic
rs.MoveFirst
  While Not rs.EOF
     Combo1.AddItem rs.Fields("职工号")
  rs.MoveNext
Wend
Set rs = Nothing
End Sub

TOP

发新话题