当前位置:编程学习 > VB >>

在vb2008中有关ado操作的问题

        Dim conn As New ADODB.Connection 
        Dim rs As New ADODB.Recordset
        Dim Str1 As String
        Dim Str2 As String
        Dim Str3 As String
        Dim sql As String
        Str1 = "Provider=Microsoft.Jet.OLEDB.4.0;"
        Str2 = "Data Source=" & Application.StartupPath & "\用户信息库.mdb;"
        Str3 = "Jet OLEDB:Database Password="
        conn.Open(Str1 & Str2 & Str3)
        If Trim(txtUserName.Text) = "" Then  '检测用户名正确与否

            MsgBox("用户名不能为空,请重新输入!")
            txtUserName.Focus()
        Else
            sql = "select * from 用户信息表 where 用户名  = '" & txtUserName.Text & "'"
            rs.Open(sql, conn, 3, 3)
            If rs.EOF = True Then
                MsgBox("用户名不存在,请重新输入!")
                txtUserName.Text= ""
                txtUserName.Focus()
            Else           '检测密码正确与否
                               If rs.Fields(2) = Trim(txtPassword.Text) Then                    rs.Close()
                    Me.Close()
                    FormMain.Show()
                Else
                    MsgBox("密码错误,请重新输入!")
                End If

            End If

        End If
就是红色标注的那句报错,提示是 无法将类型为“ADODB.InternalField”的对象强制转换为类型“System.String”。
在vb6中是没有错的。请问这怎么解决 --------------------编程问答-------------------- http://download.csdn.net/detail/veron_04/3827200 --------------------编程问答-------------------- 你得看看rs.Fields(2)字段是什么类型的.
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,