Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can a DataReader be used to populate a DataGrid? 1

Status
Not open for further replies.

emaduddeen

Programmer
Mar 22, 2007
184
US
Hi Everyone,

Can a DataReader be used to populate a DataGridView? If yes can you show me what coding I need to use to do this?

Thanks.

Truly,

Emad
 
Code:
        Me.DataGridView1.Columns.Clear()
        For i As Integer = 0 To MyDataReader.FieldCount - 1
            Me.DataGridView1.Columns.Add(MyDataReader.GetName(i), MyDataReader.GetName(i))
        Next

        While MyDataReader.Read
            Dim row(MyDataReader.FieldCount - 1) As Object
            MyDataReader.GetValues(row)
            Me.DataGridView1.Rows.Add(row)
        End While
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top