| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 680 人关注过本帖
标题:求助,登录窗体连接 Access 是数据库错误
取消只看楼主 加入收藏
迷茫乞丐
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2014-5-24
收藏
 问题点数:0 回复次数:0 
求助,登录窗体连接 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
快速回复:求助,登录窗体连接 Access 是数据库错误
数据加载中...
 
   



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

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