0

这是我在 ojt 中的项目。我在 ds(DataSet) 中遇到问题,错误说它为空,现在,我的问题是,我该如何解决这个问题?

Private Sub RefreshData()
    If Not con.State = ConnectionState.Open Then
        con.Open()
    End If

    Dim dt As New DataTable("SELECT ID as [ID], " & _
                                         "fname as [NAME], lname " & _
                                     "FROM asdf ORDER by ID")
    If ds IsNot Nothing And ds.Tables("asdf") IsNot Nothing Then****this part is were i        get the error***
        da.Fill(dt, "asdf")
    End If
    con.Close()
    maxrows = ds.Tables("asdf").Rows.Count
    inc = -1
End Sub
4

1 回答 1

0

DataTable 构造函数接收数据表的名称,这是可选的。您需要实例化 DataAdapter。

Private Sub RefreshData()
    Dim Sql="SELECT ID as [ID],fname as [NAME], lname FROM asdf ORDER by ID"
    Dim con as new OleDbConnection("your_connection_string_here")
    Dim da as new OleDbDataAdapter(Sql,con)
    Dim dt As New DataTable
    da.Fill(dt)
    ...
End Sub
于 2012-05-19T05:50:41.813 回答