Filling a DataGridView from SQLReader

后端 未结 1 331
南旧
南旧 2021-01-18 03:40

Im a little stuck on some code that im writing

An outline is that i am reading some data in from an SQL database and wantint to display it in a DataGridView on a for

相关标签:
1条回答
  • 2021-01-18 04:14

    You can't bind a datareader directly to a datagridview in WinForms. Instead you could load a datatable with your reader and assign the datatable to the datasource of the DataGridView

    Dim dt = new DataTable()
    dt.Load(reader)
    DataGridView1.AutoGenerateColumns = True
    DataGridView1.DataSource = dt
    DataGridView1.Refresh()
    
    0 讨论(0)
提交回复
热议问题