| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 583 人关注过本帖
标题:[求助]问一个VB连接数据库失败的问题,谢谢大虾们了!
取消只看楼主 加入收藏
greatcc
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-6-24
收藏
 问题点数:0 回复次数:0 
[求助]问一个VB连接数据库失败的问题,谢谢大虾们了!

遍好了后调试总“连接到数据库出错”,没弄清楚到底是哪里有问题,数据库是用ACCESS转换的SQL数据库,请大虾们多多指点。 VB代码如下:

Option Explicit

Private Sub Command1_Click() If ConenctToDatabase And VerifyUser Then On Error Resume Next If LoginStat = 0 Then Form2.Show DoEvents Unload Me ElseIf LoginStat = 1 Then Dim i As Long For i = Forms.Count - 1 To 0 Step -1 Unload Forms(i) Next i Form2.Show DoEvents End If LoginStat = 2 End If End Sub

Private Function ConenctToDatabase() As Boolean On Error GoTo ErrorHandler Dim DBName As String, ServerAdd As String, UserName As String, UserPwd As String ServerAdd = "192.168.0.1" DBName = "bbb" UserName = "sa" UserPwd = "" Set AdoCon = New ADODB.Connection AdoCon.ConnectionTimeout = 10 AdoCon.CursorLocation = adUseClient AdoCon.ConnectionString = "uid=" & UserName & ";pwd=" & UserPwd & _ ";driver={SQL Server};server=" & ServerAdd & _ ";database=" & DBName & ";dsn=''" AdoCon.Open ConenctToDatabase = True Exit Function ErrorHandler: MsgBox "连接到数据库出错", vbCritical, "出现错误" Exit Function End Function

Private Function VerifyUser() As Boolean On Error GoTo ErrorHandler Dim strSQL As String strSQL = "SELECT * FROM UserInfo WHERE UserName='" & Text(0) _ & "' AND UserPwd='" & Text(1) & "'" Set RsAdo = New ADODB.Recordset RsAdo.Open strSQL, AdoCon, adOpenStatic, adLockReadOnly If RsAdo.EOF Then MsgBox "用户名或密码错误,请重新输入!", vbCritical, "用户登录" Text(0).SetFocus Exit Function End If UserName = RsAdo("UserType") CloseRsAdo VerifyUser = True Exit Function ErrorHandler: MsgBox "验证用户信息出错", vbCritical, "出现错误" Exit Function End Function

Private Sub Form_Load() If App.PrevInstance Then End End Sub

Private Sub Form_Unload(Cancel As Integer) On Error Resume Next If Forms.Count = 1 Then If MsgBox("您确定要退出本系统吗?", vbInformation + vbYesNo, "退出系统") = vbYes Then AdoCon.Close End Else: Cancel = 1 End If End If End Sub

Private Sub text_GotFocus(Index As Integer) Text(Index).SelStart = 0 Text(Index).SelLength = Len(Text(Index)) End Sub

Private Sub Command2_Click() Unload Me End Sub

搜索更多相关主题的帖子: 数据库 失败 
2005-06-24 10:09
快速回复:[求助]问一个VB连接数据库失败的问题,谢谢大虾们了!
数据加载中...
 
   



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

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