vb访问数据库啊!!
来源:百度知道 编辑:UC知道 时间:2024/05/29 15:25:32
当他执行下一句Set rs1 = db.OpenRecordset("学生成绩查询", dbOpenDynaset)时,说类型不匹配!我该怎么改才能使他类型匹配并能访问我弄好的这个数据库?我的数据库就是一个表“学生成绩查询”里面有些小数据!
Option Explicit
Dim db As Database
Dim rs1 As Recordset
Private Sub Command1_Click()
Dim strreserch As String
Dim index As Integer
strreserch = "学号='" & Trim(Text1.Text) & "'"
rs1.FindFirst strreserch
If rs1.NoMatch Then
MsgBox "数据库中没有这个人,请重新输入!"
Else
For index = 0 To 4
Form2.Text1(index).Text = rs1.Fields(index).Value
Next
MsgBox "已经找到此人,信息显示在Form2中"
Unload Me
End If
rs1.Close
db.Close
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Set db = OpenDatabase(App.Path & "\vb1.mdb")
Set rs1 = db.OpenRecordset("学生成绩查询", dbOpenDynaset)
End Sub
我用的是DAO的
Option Explicit
Dim db As Database
Dim rs1 As Recordset
Private Sub Command1_Click()
Dim strreserch As String
Dim index As Integer
strreserch = "学号='" & Trim(Text1.Text) & "'"
rs1.FindFirst strreserch
If rs1.NoMatch Then
MsgBox "数据库中没有这个人,请重新输入!"
Else
For index = 0 To 4
Form2.Text1(index).Text = rs1.Fields(index).Value
Next
MsgBox "已经找到此人,信息显示在Form2中"
Unload Me
End If
rs1.Close
db.Close
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Set db = OpenDatabase(App.Path & "\vb1.mdb")
Set rs1 = db.OpenRecordset("学生成绩查询", dbOpenDynaset)
End Sub
我用的是DAO的
可以的写的详细些吗?你看一下你引用的是ADO库还是DAO库。
我试了一下你的load代码 没有出现不匹配的现象啊!用了一个data控件,然后数据库用97版本的,然后就load了。。。
就一句代码不好判断