错误3709连接无法用于执行此操作,报错rs.Open strSql, dbConn, adOpenForwardOnly, adLockReadOnly
我完全按照书上的例题来做,但是不管做什么,rs.OpenstrSql,dbConn,adOpenForwardOnly,adLockReadOnly老是报错,跪求指导Su...
我完全按照书上的例题来做,但是不管做什么, rs.Open strSql, dbConn, adOpenForwardOnly, adLockReadOnly老是报错,跪求指导
Sub Main() (模块)
Dim connectionstring As String
connectionstring = " provider=Microsoft.Jet.oledb.4.0;" & "data source= firework.mdb"
conn.Open connectionstring
If ConnectToDatabase = False Then
MsgBox "连接数据库出错!"
End
End If
loginOK = False
cmdType = ""
frmLogin.Show vbModal
Unload frmLogin
If loginOK Then
MDIForm1.Show
End If
End Sub
'连接到数据库
Function ConnectToDatabase() As Boolean
On Error GoTo ERR_CONN
'设置服务器名称,数据库名称,登录名(此时假设密码为空)
dbConn.connectionstring = "dsn=summer;Database=firework;uid=sa;pwd="
'dbConn.ConnectionString = "Provider=msdasql;Database=firework;server=computer;uid=sa;pwd="
dbConn.Open
ConnectToDatabase = True
Exit Function
ERR_CONN:
ConnectToDatabase = False
End Function
*****************************************************************************************
Option Explicit(另一个窗口的部分代码)
Dim rs As New ADODB.Recordset
Dim strSql As String
Private Sub Form_Load()
strSql = "Select type_id,type_name from type Order By type_id"
rs.Open strSql, dbConn, adOpenForwardOnly, adLockReadOnly
Do While Not rs.EOF
cboType.AddItem (rs.Fields("type_name").Value)
cboType.ItemData(cboType.NewIndex) = rs.Fields("type_id").Value
rs.MoveNext
Loop
rs.Close
cboType.ListIndex = 0
End Sub 展开
Sub Main() (模块)
Dim connectionstring As String
connectionstring = " provider=Microsoft.Jet.oledb.4.0;" & "data source= firework.mdb"
conn.Open connectionstring
If ConnectToDatabase = False Then
MsgBox "连接数据库出错!"
End
End If
loginOK = False
cmdType = ""
frmLogin.Show vbModal
Unload frmLogin
If loginOK Then
MDIForm1.Show
End If
End Sub
'连接到数据库
Function ConnectToDatabase() As Boolean
On Error GoTo ERR_CONN
'设置服务器名称,数据库名称,登录名(此时假设密码为空)
dbConn.connectionstring = "dsn=summer;Database=firework;uid=sa;pwd="
'dbConn.ConnectionString = "Provider=msdasql;Database=firework;server=computer;uid=sa;pwd="
dbConn.Open
ConnectToDatabase = True
Exit Function
ERR_CONN:
ConnectToDatabase = False
End Function
*****************************************************************************************
Option Explicit(另一个窗口的部分代码)
Dim rs As New ADODB.Recordset
Dim strSql As String
Private Sub Form_Load()
strSql = "Select type_id,type_name from type Order By type_id"
rs.Open strSql, dbConn, adOpenForwardOnly, adLockReadOnly
Do While Not rs.EOF
cboType.AddItem (rs.Fields("type_name").Value)
cboType.ItemData(cboType.NewIndex) = rs.Fields("type_id").Value
rs.MoveNext
Loop
rs.Close
cboType.ListIndex = 0
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询