我已经查询了我的 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
最佳答案
'尝试以下功能
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
关于mysql - 如何填充 datagridview VB.Net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20145171/