回 帖 发 新 帖 刷新版面

主题:一个数据库记录读取问题

我使用以下代码将一字段添加到COMBOBOX里
        Dim conn1 As New OleDbConnection
        Dim strString As String
        Dim cmd1 As OleDbCommand
        Dim s1 As String
        Dim dr1 As OleDbDataReader
        strString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;"  
        conn1 = New OleDbConnection(strString)
        conn1.Open()
        s1 = "select subname from subject"
        cmd1 = New OleDbCommand(s1, conn1)
        dr1 = cmd1.ExecuteReader
        dr1.Read()
        Do Until dr1.Read = False
            ComboBox1.Items.Add(dr1(0))
        Loop
        dr1.Close()
        conn1.Close()
但是,在comobox里面第一条记录没有读进去,不知道是哪儿出问题了?请各位看看!!!

回复列表 (共1个回复)

沙发

Dim conn1 As New OleDbConnection
        Dim strString As String
        Dim cmd1 As OleDbCommand
        Dim s1 As String
        Dim dr1 As OleDbDataReader
        strString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;"  
        conn1 = New OleDbConnection(strString)
        conn1.Open()
        s1 = "select subname from subject"
        cmd1 = New OleDbCommand(s1, conn1)
        dr1 = cmd1.ExecuteReader
        dr1.Read()//去掉这行即可,这行已经是读了一条纪录了
        Do Until dr1.Read = False
            ComboBox1.Items.Add(dr1(0))
        Loop
        dr1.Close()
        conn1.Close()
[color=800000][/color][color=800080]dr1.Read()//去掉这行即可,这行已经是读了一条纪录了[/color]

我来回复

您尚未登录,请登录后再回复。点此登录或注册