指定的初始化字符串不符合 ole db 规定
VB运行时说"指定的初始化字符串不符合oledb规定"我的代码如下:PrivateSubForm_Load()DimconnstrAsStringconnstr="DBQ...
VB运行时 说 "指定的初始化字符串不符合 ole db 规定"我的代码如下:Private Sub Form_Load()
Dim connstr As String
connstr = "DBQ=" + App.Path + "\address.mdb" + ";DRIVER={Microsoft Access Driver(*.mdb)}:"
conn.Open connstr
Set rst = New ADODB.Recordset
rst.Open "select*from address", conn, 1, 3
rst.MoveFirst
Text1.Text = rst.Fields(0)
Text2.Text = rst.Fields(1)
Text3.Text = rst.Fields(2)
Text4.Text = rst.Fields(3)
Text5.Text = rst.Fields(4)
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
End Sub 我按调试之后, conn.open connstr 变成黄色 怎么弄啊?高手解决下 谢谢 展开
Dim connstr As String
connstr = "DBQ=" + App.Path + "\address.mdb" + ";DRIVER={Microsoft Access Driver(*.mdb)}:"
conn.Open connstr
Set rst = New ADODB.Recordset
rst.Open "select*from address", conn, 1, 3
rst.MoveFirst
Text1.Text = rst.Fields(0)
Text2.Text = rst.Fields(1)
Text3.Text = rst.Fields(2)
Text4.Text = rst.Fields(3)
Text5.Text = rst.Fields(4)
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
End Sub 我按调试之后, conn.open connstr 变成黄色 怎么弄啊?高手解决下 谢谢 展开
2个回答
2013-10-18
展开全部
公用模块代码:
Public UserName As String
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
'SQL是要执行的SQL语句,MsgString是系统提示信息,函数返回一个数据集对象
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection '创建连接
cnn.Open ConnectString '打开连接
'判断字符串中是否含有指定内容
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & "query succesfull"
Else
'创建数据集对象
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
rst.MoveLast '获得RecordCount值
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & "条记录"
End If
ExecuteSQL_Exit:
'中断连接
Set rst = Nothing
Set cnn = Nothing
Exit Function
'错误类型判断
ExecuteSQL_Error:
MsgString = "查询错误:" & Err.Description
Resume ExecuteSQL_Exit
End Function
'连接数据库
Public Function ConnectString() As String
Dim str As String
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If
ConnectString = "PROVIDER=Microsoft.jet.OLEDB.3.51;Persist Security Info=Flase;Data Source=" & str & "Student.mdb"
End Function
窗体中的代码:
Option Explicit
Public OK As Boolean
'记录确定次数
Dim miCount As Integer
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim msgtext As String
'定义变量
UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from user where user_ID ='" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, msgtext)
If mrc.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus '
'判断用户是否存在
Else
If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPassword.SetFocus
'判断密码是否正确
txtPassword.Text = ""
End If
End If
End If
miCount = miCount + 1
If miCount = 3 Then
Me.Hide
End If
Exit Sub
End Sub
Private Sub Form_Load()
OK = False
miCount = 0
End Sub
Public UserName As String
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
'SQL是要执行的SQL语句,MsgString是系统提示信息,函数返回一个数据集对象
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection '创建连接
cnn.Open ConnectString '打开连接
'判断字符串中是否含有指定内容
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then
cnn.Execute SQL
MsgString = sTokens(0) & "query succesfull"
Else
'创建数据集对象
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
rst.MoveLast '获得RecordCount值
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & "条记录"
End If
ExecuteSQL_Exit:
'中断连接
Set rst = Nothing
Set cnn = Nothing
Exit Function
'错误类型判断
ExecuteSQL_Error:
MsgString = "查询错误:" & Err.Description
Resume ExecuteSQL_Exit
End Function
'连接数据库
Public Function ConnectString() As String
Dim str As String
str = App.Path
If Right(str, 1) <> "\" Then
str = str + "\"
End If
ConnectString = "PROVIDER=Microsoft.jet.OLEDB.3.51;Persist Security Info=Flase;Data Source=" & str & "Student.mdb"
End Function
窗体中的代码:
Option Explicit
Public OK As Boolean
'记录确定次数
Dim miCount As Integer
Private Sub cmdCancel_Click()
End
End Sub
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim mrc As ADODB.Recordset
Dim msgtext As String
'定义变量
UserName = ""
If Trim(txtUserName.Text = "") Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus
Else
txtSQL = "select * from user where user_ID ='" & txtUserName.Text & "'"
Set mrc = ExecuteSQL(txtSQL, msgtext)
If mrc.EOF = True Then
MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
txtUserName.SetFocus '
'判断用户是否存在
Else
If Trim(mrc.Fields(1)) = Trim(txtPassword.Text) Then
OK = True
mrc.Close
Me.Hide
UserName = Trim(txtUserName.Text)
Else
MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtPassword.SetFocus
'判断密码是否正确
txtPassword.Text = ""
End If
End If
End If
miCount = miCount + 1
If miCount = 3 Then
Me.Hide
End If
Exit Sub
End Sub
Private Sub Form_Load()
OK = False
miCount = 0
End Sub
2013-10-18
展开全部
connstr = "DBQ=" + App.Path + "\address.mdb" + ";DRIVER={Microsoft Access Driver(*.mdb)}:"
改一下connstr = "PROVIDER=Microsoft.jet.OLEDB.3.51;Persist Security Info=Flase;Data Source=" & App.Path & "\address.mdb"如果是高版本ADO,上面的3.51改成4.0
改一下connstr = "PROVIDER=Microsoft.jet.OLEDB.3.51;Persist Security Info=Flase;Data Source=" & App.Path & "\address.mdb"如果是高版本ADO,上面的3.51改成4.0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询