标题:求助,登录窗体连接 Access 是数据库错误
只看楼主
迷茫乞丐
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2014-5-24
 问题点数:0 回复次数:1 
求助,登录窗体连接 Access 是数据库错误
哪位大神帮帮忙 一运行就出现
实时错误
from 子句语法错误
然后显示 rst0.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic 这句话错误

登录界面程序如下

模块代码
Public usertype As String
Public username As String
Public gst As String

Public Function ConnectString() As String

 ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=House.mdb;Persist Security Info=False"
End Function
Public Function executeSQL(ByVal SQL As String) As ADODB.Recordset

Dim cnn As ADODB.Connection
Dim rst0 As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open ConnectString
   Set rst0 = New ADODB.Recordset
   rst0.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
   Set executeSQL = rst0
   
End Function



Public Function testtxt(txt As String) As Boolean
If Trim(txt) = "" Then
  testtxt = False
Else
  testtxt = True
End If

End Function




Dim miCount As Integer
Private Sub cmdcancel_click()
Me.Hide
End
End Sub
窗体代码如下
Private Sub cmdok_click()
Dim i As Integer
Dim SQL As String
Dim rst As ADODB.Recordset
If Comb.Text = "" Then
    MsgBox "请选择用户类型!", vbOKOnly + vbExclamation, "警告"
    Comb.SetFocus
    Exit Sub
End If
If txtname.Text = "" Then
    MsgBox "请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
    txtname.SetFocus
    txtname.Text = ""
    Exit Sub
End If
Select Case Comb.Text
  Case "系统管理员"
    usertype = "0"
 
  Case "普通用户"
    usertype = "1"
 
End Select
If txtpwd.Text = "" Then
    MsgBox "请重输入用户密码!", vbOKOnly + vbExclamation, "警告"
    txtpwd.SetFocus
    Exit Sub
End If
      SQL = "select * from user where user_name = '" & txtname.Text & "'"
      Set rst = executeSQL(SQL)
If rst.EOF Then
    MsgBox "没有这个用户,请重新输入用户名!", vbOKOnly + vbExclamation, "警告"
    txtname.SetFocus
    txtname.Text = ""
    txtpwd.Text = ""
    Exit Sub
End If
If rst.Fields(2) <> usertype Then
         MsgBox "用户名与用户类型不匹配!", vbOKOnly + vbExclamation, "警告"
        txtname.Text = ""
        txtpwd.Text = ""
        Exit Sub
End If
If Trim(rst.Fields(1)) = Trim(txtpwd.Text) Then
    username = Trim(txtname.Text)
    rst.Close
    main.Show
    Unload Me
Else
    MsgBox "输入密码不正确,请重新输入!", vbOKOnly + vbExclamation, "警告"
    txtpwd.SetFocus
    txtpwd.Text = ""
    miCount = miCount + 1
    If miCount = 3 Then
        Me.Hide
        Exit Sub
    End If
End If
End Sub

Private Sub Form_Load()
miCount = 0
 Comb.AddItem "系统管理员"

 Comb.AddItem "普通用户"

Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2
End Sub
搜索更多相关主题的帖子: 数据库 False 
2014-05-24 17:40
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
给你一个例子`~~自己去参考~
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VB数据\db1.mdb;Persist Security Info=False"
sql = "select * from [table] where uesrname='" & Text1.Text & "'"
conn.CursorLocation = adUseClient
conn.connectionstring = connstr
conn.Open
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1
'Set rs = conn.Execute(sql)
'rs.Open sql, conn, adOpenStatic, adLockOptimistic
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If
If Text2.Text <> rs("password") Then
MsgBox "密码错误"
rs.Close
conn.Close
Else
rs.Close
conn.Close
Form2.Show
Unload Me
End If
End Sub

Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim my_recordset As ADODB.Recordset
Dim connectionstring As String
Set cnn = New ADODB.Connection
Set my_recordset = New ADODB.Recordset
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:\VB数据\njzhxt.mdb;Persist Security Info=False"

End Sub
2014-05-26 10:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-431995-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.107011 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved