vb 登陆对话框

来源:百度知道 编辑:UC知道 时间:2024/06/21 14:51:43
做登陆对话框时发生点错误 请高人指点,验证用户名的确定按钮中的一句代码有问题,不过数据库连接成功的!
If Trim(Adodc1.Recordset.Fields(0)) = txtUserName.Text And Trim(Adodc1.Recordset.Fields(1)) = txtPassword.Text Then
主程序界面.Show
LoginSucceeded = True
Me.Hide
输入用户名和密码后,提示
“实时错误 91 对象变量或with块变量未设置”

错误行是:If Trim(Adodc1.Recordset.Fields(0)) = txtUserName.Text And Trim(Adodc1.Recordset.Fields(1)) = txtPassword.Text Then

=========================================================
看来的确是Adodc1.Recordset.Fields(0) 和 Adodc1.Recordset.Fields(1)有错误啊,不过这个要怎么改正呢?

单看语句,没有错误,给出的错误信息是什么?

有可能 Adodc1.Recordset.Fields(1) 是空的(Null,未设密码)造成错误。
可以这样改:
Trim(Adodc1.Recordset.Fields(1) & "") = txtPassword.Text
==================
那就先确认 Adodc1.Recordset.Fields(0) 和 Adodc1.Recordset.Fields(1) 的值,比如先这样写:
Debug.Print Adodc1.Recordset.Fields(0)
Debug.Print Adodc1.Recordset.Fields(1)
看看是否出错

数据库连接错误!请查看数据库连接语句是否正确啦!