设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3444|回复: 3
打印 上一主题 下一主题

[求助]VB怎么连ACCESS

[复制链接]
跳转到指定楼层
1#
发表于 2005-10-28 23:14:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
VB怎么连ACCESS?在登录窗口的cmdOK_Click()事件里和在模块里怎么写啊?我现在是按了确定后没反应,下面是模块下的代码

Option Explicit

Public con As New ADODB.Connection

Public Function connecttoserver() As Boolean

On Error GoTo ConnectErr

    '连接到数据库

    con.CursorLocation = adUseClient

    con.ConnectionString = "provider=microsoft.jet.oledb.4.0;""Data sourct=" & App.Path & "\emp.mdb;"

    con.ConnectionTimeout = 5          '20秒等待时间

    con.Open                           '打开连接

    connecttoserver = True

Exit Function

ConnectErr:

    connecttoserver = False

    MsgBox "错误代码:" & Err.Number & vbCrLf & _

            "错误描述:" & Err.Description, vbCritical + vbOKOnly, "连接错误"

End Function

Public Function ExecuteSQL(ByVal strsql As String) As Boolean

On Error Resume Next

    con.Execute (strsql)

    If Err.Number <> 0 Then

        MsgBox "错误代码:" & Err.Number & vbCrLf & _

                "错误描述:" & Err.Description, vbCritical + vbOKOnly, "连接错误"

        Err.Clear

        ExecuteSQL = False

    Else

        ExecuteSQL = True

    End If

End Function

Public Function DisConnect() As Boolean

On Error Resume Next

    If con.State = adStateOpen Then

        con.Close

    End If

    DisConnect = True

End Function

下面是cmdok_click()下的代码

Private Sub cmdOK_Click()

    If Text1.Text = "" Or Text2.Text = "" Then

        MsgBox "请将登陆信息填写完整!", 16 + vbOKOnly, "登录错误"

        Text1.SetFocus

    Else

        strsql = "select * from managerlist where name='" & Text1.Text & "' and pwd='" & Text2.Text & "'"

    End If

请问哪不对啊?或者少了什么语句吗?
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-10-31 18:00:00 | 只看该作者
有没什么错误提示,单看这个方法上应该没什么问题……
3#
发表于 2005-11-5 02:58:00 | 只看该作者
给一个ADO的实例您参考,以下代码由乙肝自由联盟提供:



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
4#
发表于 2006-3-8 01:11:00 | 只看该作者
access要97的版本才行,你是不是忽略这一点了?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-29 11:57 , Processed in 0.086088 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表