如何填充数据视图VB.Net

时间:2013-11-22 12:40:57

标签: mysql arrays vb.net datagridview datasource

我查询了我的MySql数据库,数据存储在名为Search Events的数据集中(我检查了这个并且它有效) 但是,当我尝试将这些数据传递到datagridview然后最终我的数组它似乎没有工作:(问题似乎是没有数据从搜索事件传递到表 任何想法??

 Dim Table As New DataGridView
    Table.DataSource = SearchEvents.Tables("Event ID")
    Dim EventID(Table.Rows.Count - 1) As String
    For i = 0 To 12
        EventID(i) = Table.Rows(0).Cells(i).Value
    Next

1 个答案:

答案 0 :(得分:0)

'尝试以下功能

    Public Sub getuserlist()
    Dim con As New MySqlConnection(ConnectionString)

    Try
        If con.State <> ConnectionState.Open Then
            con.Open()
        End If

        Dim selecttaxinv = "SELECT * FROM user_tb WHERE  user_status = 'Active' ORDER BY date_registered DESC"
        Dim myCommand As New MySqlCommand(selecttaxinv, con)
        Dim dr As MySqlDataReader
        dr = myCommand.ExecuteReader()
       yourdatagridview.Rows.Clear()
        Dim b = 1
        While dr.Read()
            Dim fullname As String = dr("fname") & " " & dr("mname") & " " & dr("lname")

            Dim row As String() = New String() {dr("user_id"), b, fullname, dr("fname"), dr("date_registered")}
            yourdatagridview.Rows.Add(row) 'print list
            b += 1
        End While
        dr.Close()


        If con.State = ConnectionState.Open Then
            con.Close()
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)

    End Try

End Sub