0

我有一个包含 3 行的 datagridview (DGV)。我想将 MySQL 查询的结果(4 行)添加到 DGV。查询的结果放置在数据集 (DS) 中。将四个 DS 行添加到 DGV 的语法是什么?

4

1 回答 1

0

您必须通过循环添加数据集中的行。

Dim myConnObj As New MySqlConnection
Dim myDataSet As New DataSet
Dim myDataAdapter As New MySqlDataAdapter
Dim myCommand As New MySqlCommand

myCommand = New MySqlCommand("Your Query", "Your Connection")
myDataAdapter = New MySqlDataAdapter(myCommand)
myDataAdapter.Fill(myDataSet, "list")

With myDataSet
   For i as integer = 0 to .Tables(0).Rows.Count - 1
       DataGridView1.Rows.Add(.Tables(0).Rows(i).Item(0).ToString(), .Tables(0).Rows(i).Item(0).ToString())

'.Rows.Add(Column1, Column2, etc...) the number of column you add should match the column count of your DataGridView

   Next
End With
于 2012-10-23T00:55:38.377 回答