如何用一个有关系的数据库填充datagridview?

时间:2016-09-20 08:03:10

标签: database vb.net datagridview

有没有办法可以用数据库中有关系的记录填充Datagridview?我想在一个Datagridview中显示所有记录。我搜索了Google但我找不到任何解决方案或示例代码。这是我的代码:

    Dim sql As String
    sql = "SELECT * FROM employee"

    Dim adapter As New OleDbDataAdapter(sql, con1)

    Dim dt As New DataTable("employee")
    adapter.Fill(dt)
    ' Assigns our DataSource on the DataGridView
    DataGridView1.DataSource = dt
    '
    Dim sql1 As String
    sql1 = "SELECT * FROM employee"
    Dim adapter1 As New OleDbDataAdapter(sql1, con1)
    Dim cmd1 As New OleDbCommand(sql1, con1)

    con1.Open()
    Dim myreader As OleDbDataReader = cmd1.ExecuteReader
    myreader.Read()
    con1.Close()

0 个答案:

没有答案