This code create the columns according your table column name.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oCn As New System.Data.SqlClient.SqlConnection("Data Source=(local);Initial Catalog=MyDatabase;Uid=sa")
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Me.DataGridView1.Rows.Clear()
Me.DataGridView1.Columns.Clear()
Dim cmd As New SqlClient.SqlCommand("select quizid,question from quiz where quizid=123", oCn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Dim i As Integer = 0
da.Fill(ds, "bpl")
If ds.Tables(0).Columns.Count > 0 Then
While (i <> ds.Tables(0).Columns.Count)
Me.DataGridView1.Columns.Add(ds.Tables(0).Columns(i).ColumnName, ds.Tables(0).Columns(i).ColumnName)
i = i + 1
End While
End If
i = 0
Dim j As Integer = 0
If ds.Tables(0).Rows.Count > 0 Then
While (j <> ds.Tables(0).Rows.Count)
Me.DataGridView1.Rows.Add()
While (i <> ds.Tables(0).Columns.Count)
Me.DataGridView1.Item(i, j).Value = ds.Tables(0).Rows(j).Item(Me.DataGridView1.Columns(i).HeaderText)
i = i + 1
End While
i = 0
j = j + 1
End While
End If
j = 0
End Sub