对象Open的方法recordset 失败
来源:百度知道 编辑:UC知道 时间:2024/05/18 07:28:16
以下为我的VB程序,不知道为什么老是提示“对象Open的方法recordset 失败”,请大家帮忙看看啊,急
Dim Con As New ADODB.Connection
Dim Res As New ADODB.Recordset
Dim sql As String
Private Sub Command1_Click()
If Text1.Text <> "" Then
If Text2.Text <> "" Then
If Text3.Text <> "" Then
If Combo1.Text <> "" Then
Set Con = New ADODB.Connection
Con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\mydb.mdb"
sql = "Select * From ȨÏÞ±í"
Set Res = New ADODB.Recordset
Res.Open sql, cn 报错后,光标指向此处
Rs.MoveFirst
For i = 0 To Rs.RecordCount - 1
If Combo1.Text = Rs.Fields("Óû§") Then
If Text1.Text = Rs.Fields("̞") Then
If Text2.Text =
Dim Con As New ADODB.Connection
Dim Res As New ADODB.Recordset
Dim sql As String
Private Sub Command1_Click()
If Text1.Text <> "" Then
If Text2.Text <> "" Then
If Text3.Text <> "" Then
If Combo1.Text <> "" Then
Set Con = New ADODB.Connection
Con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\mydb.mdb"
sql = "Select * From ȨÏÞ±í"
Set Res = New ADODB.Recordset
Res.Open sql, cn 报错后,光标指向此处
Rs.MoveFirst
For i = 0 To Rs.RecordCount - 1
If Combo1.Text = Rs.Fields("Óû§") Then
If Text1.Text = Rs.Fields("̞") Then
If Text2.Text =
1. Res.Open sql, cn
这句话里面的cn应该指的是上面的数据库连接对象con吧?你上面的con只是指定了连接字符串,并没有调用open方法来打开连接,在记录集打开之前,要先开启数据库连接
2. sql = "Select * From ȨÏÞ±í"
你这sql语句的from 后面是中国字吗????
前面那几句改为
Set Con = New ADODB.Connection
Con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\mydb.mdb"
con.open '打开数据库连接
sql = "Select * From ȨÏÞ±í"
Set Res = New ADODB.Recordset
Res.Open sql, con '打开记录集