我用VB查询Access里的数据,运行一个学生信息管理系统,怎么但一直出现: 对象refresh 的IADODC方法失败Private Sub cmdOK_Click() 
Static error_count As Integer
If txtUserName.Text = "" And txtPassword.Text = "" Then
  MsgBox "请输入用户名和密码", vbExclamation + vbOKOnly, "登陆提示"
 txtUserName.SetFocus
Else
  Adodc1.CommandType = adCmdText
  Adodc1.RecordSource = "select * from pwd where 用户名='" & txtUserName.Text & "'"
  Adodc1.Refresh
  If Adodc1.Recordset.EOF = True Then
     MsgBox "用户名不正确,请您确认后重新输入", vbExclamation + vbOKOnly, "登陆提示"
     txtUserName.Text = ""
     txtUserName.SetFocus
  Else
       Adodc1.CommandType = adCmdText
       Adodc1.RecordSource = "select * from pwd where 用户名='" & txtUserName.Text & "' and 密码='" & txtPassword.Text & "'"
       Adodc1.Refresh       '此行出错 
       If Adodc1.Recordset.EOF = True Then
          error_count = error_count + 1
          If error_count = 3 Then
             MsgBox "您是非法用户,系统即将关闭", vbCritical + vbOKOnly, "登陆提示"
             Unload Me
          Else
             MsgBox "密码不正确,请您确认后重新输入", vbExclamation + vbOKOnly, "登陆提示"
             txtPassword.Text = ""
             txtPassword.SetFocus
          End If
        Else
            If Adodc1.Recordset!权限 = "学生" Then
               qx = "学生"
               UserName = txtUserName.Text
               MsgBox "欢迎学生登陆!" & vbCrLf & vbCrLf & "你只有学生的权限!", vbInformation + vbOKOnly, "登陆提示"
               
             '  MDIForm1.sys.Enabled = False
               Login_frm.Hide
               MDIForm1.Show
              ' MDIForm1.Enabled = False
               txtUserName.Text = ""
               txtPassword.Text = ""
                              MDIForm1.student.Enabled = True
               MDIForm1.s_choice.Enabled = True
               MDIForm1.stchquery.Enabled = True
               MDIForm1.help.Enabled = True
               MDIForm1.user.Enabled = True
               MDIForm1.Command1.Enabled = True
               
               MDIForm1.denglu.Enabled = False
               MDIForm1.teacher.Enabled = False
               MDIForm1.course.Enabled = False
               MDIForm1.t_choice.Enabled = False
               MDIForm1.tequery.Enabled = False
               MDIForm1.help.Enabled = False
               MDIForm1.reports.Enabled = False
               MDIForm1.Command2.Enabled = False
               MDIForm1.Command3.Enabled = False
               MDIForm1.Command4.Enabled = False
               MDIForm1.Command5.Enabled = False
               
               
               MDIForm1.user_manage.Enabled = False
               
           ElseIf Adodc1.Recordset!权限 = "老师" Then
               qx = "老师"
               UserName = txtUserName.Text
               MsgBox "欢迎教师登陆!" & vbCrLf & vbCrLf & "你只有教师的权限!", vbInformation + vbOKOnly, "登陆提示"
               'MDIForm1.sys.Enabled = False
               Login_frm.Hide
               MDIForm1.Show
             '  MDIForm1.Enabled = False
               txtUserName.Text = ""
               txtPassword.Text = ""
                              MDIForm1.teacher.Enabled = True
               MDIForm1.course.Enabled = True
               MDIForm1.t_choice.Enabled = True
               MDIForm1.tequery.Enabled = True
               MDIForm1.help.Enabled = True
               MDIForm1.user.Enabled = True
               MDIForm1.Command2.Enabled = True
               MDIForm1.Command3.Enabled = True
               
               MDIForm1.denglu.Enabled = False
               MDIForm1.student.Enabled = False
               MDIForm1.s_choice.Enabled = False
               MDIForm1.stchquery.Enabled = False
               MDIForm1.help.Enabled = False
               MDIForm1.help.Enabled = False
               MDIForm1.reports.Enabled = False
               MDIForm1.Command1.Enabled = False
               MDIForm1.Command4.Enabled = False
               MDIForm1.Command5.Enabled = False
               
               MDIForm1.user_manage.Enabled = False
               
            ElseIf Adodc1.Recordset!权限 = "管理员" Then
               qx = "管理员"
               UserName = txtUserName.Text
               MsgBox "欢迎管理员登陆!" & vbCrLf & vbCrLf & "你有所有的权限!", vbInformation + vbOKOnly, "登陆提示"
               Login_frm.Hide
               MDIForm1.Show
            '   MDIForm1.Enabled = False
               txtUserName.Text = ""
               txtPassword.Text = ""
               
            End If
       End If
  End If
End If
End Sub

解决方案 »

  1.   

    给你2个建议1,改换ado,因为除了老土的教科书会告诉你去使用adodc控件外 实际情况是没有人用adodc控件2,把那句直接去掉,但是不保证你正确
      

  2.   

    你的ADODC控件连数据源了吗?
    要是连了就检查你的SQL语句是不是有敲错的地方!
      

  3.   


            Adodc1.Recordset.Close
           Adodc1.ConnectionString ="你的连接字符串"
    '加上面两句在这个地方
           Adodc1.CommandType = adCmdText 
           Adodc1.RecordSource = "select * from pwd where 用户名='" & txtUserName.Text & "' and 密码='" & txtPassword.Text & "'" 
           Adodc1.Refresh       '此行出错  
      

  4.   

    对啊!楼主有没有看3楼的帖子?加上连接字符串!或在ADODC控件右键属性里连。