1

我试图更改 datagridview 中的行颜色,但曾经为我工作的代码需要一个数据集。这是我用来填充我的 datagridview 的代码

    Dim sql As String
    sql = "SELECT * FROM [product info]"
    Dim adapter As New OleDbDataAdapter(sql, strcon)
    Dim dt As New DataTable("[product info]")
    adapter.Fill(dt)
    DataGridView1.DataSource = dt

    Dim sql1 As String
    sql1 = "SELECT * FROM [product info]"
    Dim adapter1 As New OleDbDataAdapter(sql1, strcon)
    Dim cmd As New OleDbCommand(sql1, strcon)
    strcon.Open()
    Dim myreader As OleDbDataReader = cmd.ExecuteReader
    myreader.Read()

    strcon.Close()

如何在这行代码中声明数据集?

4

2 回答 2

0
    Dim sql As String
    sql = "SELECT * FROM [product info]"
    Dim adapter As New OleDbDataAdapter(sql, strcon)
    Dim ds As New DataSet("[product info]")
    adapter.Fill(ds)
    DataGridView1.DataSource = ds

    Dim sql1 As String
    sql1 = "SELECT * FROM [product info]"
    Dim adapter1 As New OleDbDataAdapter(sql1, strcon)
    Dim cmd As New OleDbCommand(sql1, strcon)
    strcon.Open()
    Dim myreader As OleDbDataReader = cmd.ExecuteReader
    myreader.Read()

strcon.Close()
于 2013-04-02T11:50:22.350 回答
0
Dim ds as New Dataset("product_info")
ds.Tables.Add(dt)

将数据填充到数据表 dt 后添加这些行

于 2013-04-02T11:53:57.823 回答