| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 538 人关注过本帖
标题:帮帮忙~~
只看楼主 加入收藏
longwindwind
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-11-7
收藏
 问题点数:0 回复次数:3 
帮帮忙~~

哪位大虾帮忙看看,这是我写的登陆,怎么会出错呢?
Dim i As New ADODB.Connection
Dim j As New ADODB.Recordset

Private Sub Command1_Click()
Dim num As Integer
Dim sql As String
Set i = New ADODB.Connection
Set j = New ADODB.Recordset
i.ConnectionString = "provider=sqloledb.1;data source=(local);user id=sa;pwd=247162545;initial catalog=sdb"
i.Open
sql = "select * from s where sno='" & Trim(Text1.Text) & "'"
j.Open sql, i, adOpenStatic, adLockOptimistic
If j.RecordCount > 0 Then
If j.Fields("sn") = Text2 Then
MsgBox "登陆成功"
Else
If num > 3 Then
MsgBox "超出登陆次数"
Unload Me
End If
MsgBox "密码不对"
Text2.Text = ""
Text2.SetFocus
Exit Sub
End If
Else
MsgBox "用户名不正确"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
End Sub

搜索更多相关主题的帖子: sql initial source local 
2005-11-10 19:10
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
以下是引用longwindwind在2005-11-10 19:10:44的发言:

哪位大虾帮忙看看,这是我写的登陆,怎么会出错呢?
Dim i As New ADODB.Connection
Dim j As New ADODB.Recordset

Private Sub Command1_Click()
Dim num As Integer
Dim sql As String
Set i = New ADODB.Connection
Set j = New ADODB.Recordset

i.ConnectionString = "provider=sqloledb.1;data source=(local);user id=sa;pwd=247162545;initial catalog=sdb"
i.Open
sql = "select * from s where sno='" & Trim(Text1.Text) & "'"
j.Open sql, i, adOpenStatic, adLockOptimistic
If j.RecordCount > 0 Then
If j.Fields("sn").Value = Text2.Text Then
MsgBox "登陆成功"
Else
If num > 3 Then
MsgBox "超出登陆次数"
Unload Me
End If
MsgBox "密码不对"
Text2.Text = ""
Text2.SetFocus
Exit Sub
End If
Else
MsgBox "用户名不正确"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
End Sub

红字的都是楼主程序可能出错的地方。
首先
Set i = New ADODB.Connection
Set j = New ADODB.Recordset
这里就有错误,单看这里好像没有错误。
但是
Dim i As New ADODB.Connection
Dim j As New ADODB.Recordset
因为有着两句就会出错。
楼主已经用New关键字声明并创建了i和j两个对象,而楼主又接着。
Set i = New ADODB.Connection
Set j = New ADODB.Recordset
重复创建了这个两个对象,这两个对象已经存在。所以有可能出错。

2005-11-11 13:00
longwindwind
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-11-7
收藏
得分:0 
我可以在通用里面把
Dim i As New ADODB.Connection
Dim j As New ADODB.Recordset
改成
Dim i As ADODB.Connection
Dim j As ADODB.Recordset
然后再设定 set i=new ADODB.Connection
set j=new ADODB.Recordset
这样可以吗?
2005-11-12 12:32
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
以下是引用longwindwind在2005-11-12 12:32:48的发言:
我可以在通用里面把
Dim i As New ADODB.Connection
Dim j As New ADODB.Recordset
改成
Dim i As ADODB.Connection
Dim j As ADODB.Recordset
然后再设定 set i=new ADODB.Connection
set j=new ADODB.Recordset
这样可以吗?

可以这样应该不会出错误了。

2005-11-12 15:59
快速回复:帮帮忙~~
数据加载中...
 
   



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

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