请VB大师帮忙,一个文件有二张表用Option1、Option2、来打开控制,点击Option1把表一显示在List1上!
PublicconnAsNewADODB.Connection'定义数据连接字符串PublicrsAsNewADODB.Recordset'定义记录集Dimdb$,i%,...
Public conn As New ADODB.Connection '定义数据连接字符串
Public rs As New ADODB.Recordset '定义记录集
Dim db$, i%, jj%
Private Sub Form_Load()
db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & "C:\Users\Administrator\Desktop\新建文件夹 (2)\xing guang.mdb"
conn.CursorLocation = adUseClient
conn.Open db '打开数据库连接
rs.Open "表一", conn, adOpenKeyset, adLockPessimistic '打开记录集
If rs.RecordCount > 0 Then
rs.MoveFirst
List1.Clear
For i = 0 To rs.RecordCount - 1
List1.AddItem rs.Fields("301室")
rs.MoveNext
Next i
rs.MoveFirst
List1.Selected(0) = True
End If
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
End Sub
Private Sub List1_Click()
If List1.ListCount > 0 Then
jj = List1.ListIndex
rs.MoveFirst
rs.Move jj
gzg001.Text = rs.Fields("名称)")
gzg002.Text = rs.Fields("姓别")
gzg003.Text = rs.Fields("年月日")
End If
End Sub 展开
Public rs As New ADODB.Recordset '定义记录集
Dim db$, i%, jj%
Private Sub Form_Load()
db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & "C:\Users\Administrator\Desktop\新建文件夹 (2)\xing guang.mdb"
conn.CursorLocation = adUseClient
conn.Open db '打开数据库连接
rs.Open "表一", conn, adOpenKeyset, adLockPessimistic '打开记录集
If rs.RecordCount > 0 Then
rs.MoveFirst
List1.Clear
For i = 0 To rs.RecordCount - 1
List1.AddItem rs.Fields("301室")
rs.MoveNext
Next i
rs.MoveFirst
List1.Selected(0) = True
End If
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
End Sub
Private Sub List1_Click()
If List1.ListCount > 0 Then
jj = List1.ListIndex
rs.MoveFirst
rs.Move jj
gzg001.Text = rs.Fields("名称)")
gzg002.Text = rs.Fields("姓别")
gzg003.Text = rs.Fields("年月日")
End If
End Sub 展开
2个回答
展开全部
Private Sub Option1_Click()
If rs.state = 1 Then rs.Close
List1.Clear
rs.Open "表一", conn, 1, 1
Do Until rs.EOF
List1.AddItem rs("301室")
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Option2_Click()
If rs.state = 1 Then rs.Close
List1.Clear
rs.Open "表二", conn, 1, 1
Do Until rs.EOF
List1.AddItem rs("301室")
rs.MoveNext
Loop
rs.Close
End Sub
If rs.state = 1 Then rs.Close
List1.Clear
rs.Open "表一", conn, 1, 1
Do Until rs.EOF
List1.AddItem rs("301室")
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Option2_Click()
If rs.state = 1 Then rs.Close
List1.Clear
rs.Open "表二", conn, 1, 1
Do Until rs.EOF
List1.AddItem rs("301室")
rs.MoveNext
Loop
rs.Close
End Sub
更多追问追答
追问
大师啊大师,你回我一下好不好
追答
我不是已经写出代码给你了么?有什么不对的么?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询