回 帖 发 新 帖 刷新版面

主题:這問題怎麼解決!VB.NET

Dim cn As New OleDbConnection("Provider=MSDAORA.1;User ID=pos;Data Source=newpos;user id=good;password=good")
        Dim ds As New DataSet
        Dim dt As DataTable = ds.Tables.Add("breedb")
        'Prepare Datatable
        Dim cmd As New OleDbCommand("select *from breedb", cn)


        'Prepare Command
        cn.Open()


        Dim rdr As OleDbDataReader = cmd.ExecuteReader
        Dim intfirstculumn As Integer = rdr.GetOrdinal("chang_no")
        Dim row As DataRow

        Do While rdr.Read()
            row = dt.NewRow()
            row("CHANGE_NO") = rdr(intfirstculumn)

            'Fetch data from other columns
            dt.Rows.Add(row)
        Loop
        rdr.Close()

        Me.DataGrid1.DataSource = ds.Tables(0)
錯誤提示為“類型System.IndexOutofRangeException”其它信息“Change_no”

回复列表 (共2个回复)

沙发

就IndexOutofRangeException来说是索引越界。你单步调试看看是哪里报的错

板凳

row = dt.NewRow這裡報的錯

我来回复

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