VB+sql 史诗错误'3001'
VB6.0 + SQL 2000
数据库名:popo 表名:帐号 内容:学号,密码
要求实现和数据库中帐号密码对比登陆
代码如下:
Dim str As String
Dim rs As New ADODB.Recordset
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=popo;Data Source=6C6CF07F486A42C "
cn.Open
If Text1.Text = " " Then
MsgBox "请输入学号! ", vbOKOnly + vbInformation, "用户登陆 "
Text1.SetFocus
Exit Sub
Else
GetConnected
Set rs = New ADODB.Recordset
student = "select * from 帐号 where 学号= ' " & Text1.Text & " ' "
rs.Open popo, cn, adOpenDynamic, adLockOptimistic
If rs.EOF = True And rs.BOF = True Then
Text1.Text = " "
Text2.Text = " "
MsgBox "没有这个用户,请重新输入! ", vbOKOnly + vbExclamation, "警告 "
Text1.SetFocus
Else
If Text2.Text = rs!密码 Then
rs.Close
Me.Hide
Form4.Show
Form4.Label2.Caption = Text1.Text
Unload Me
Else
MsgBox "密码错误! "
Text1.Text = " "
Text2.Text = " "
Text1.SetFocus
End If
End If
End If
End Sub
头两行写在通用里面,运行的时候出现下面报错;
参数类型不正确,或不在可以 接受的范围之内,或与其他参数冲突.
能帮我看看怎么回事么?
[解决办法]
有了Dim cn As New ADODB.Connection 可省略 Set cn = New ADODB.Connection这一句
要么就这样定义:
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection ’这时这一句一定要有
你所出现的错误,我想可能是连接数据库那出了问题,就是cn.open 出了问题
[解决办法]
rs.Open popo, cn, adOpenDynamic, adLockOptimistic
这句的 popo是什么?
建议楼主贴上错误描述
[解决办法]
Set rs = New ADODB.Recordset
student = "select * from 帐号 where 学号= ' " & Text1.Text & " ' "
rs.Open student , cn, adOpenDynamic, adLockOptimistic
