VB 要求变量?

来源:百度知道 编辑:UC知道 时间:2024/05/04 22:09:07
Private Sub Command1_Click()
Dim zhuce As New ADODB.Recordset
If Text1.Text = "" Or Text2.Text = "" Then
MsgBox "请填写完整的信息!"
Exit Sub
Else

zhuce.Open "select * from tbluser where username='" & Trim(Text1.Text) & "'", conn, adOpenKeyset, adLockOptimistic
If zhuce.RecordCount > 0 Then
MsgBox "该帐号已存在,请重新输入!"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
zhuce.Close
Exit Sub
Else
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("username") = Trim(Text1.Text)
Adodc1.Recordset.Fields("password") = Trim(Text2.Text)
Adodc1.Recordset.Update
Adodc1.Refresh
End If
MsgBox "注册成功!"
End If
End Sub
在运行时出现 '要求变量' 的错误
请高手

Adodc1.Recordset.AddNew 没错
可能是要在
Else 和 Adodc1.Recordset.AddNew
之间加一句zhuce.Close
因为如果判断可以注册的话那么zhuce打开的数据库就没有关闭

另外Adodc1.Refresh 一句也有点嫌疑,试着把这句去掉试试

试试行不
不行的话可以把程序发到我邮箱里

dim con as new ADODB.Connection
Dim zhuce As New ADODB.Recordset
con.connextionString="连接字符串"
con.open
zhuce.Open "select * from tbluser where username='" & Trim(Text1.Text) & "'", conn, adOpenKeyset, adLockOptimistic,-1

"Adodc1.Recordset.AddNew"???
应该是zhuce.AddNew吧
zhuce.Fields("username") = Trim(Text1.Text)'
zhuce.Fields("password") = Trim(Text1.Text)
zhuce.Update
zhuce.Refresh