Datareader to Datagrid

B

BC

Hi,

Been searching the newgroups but haven't found an
answer.

I'm used to binding disconnected ADO recordsets
to Datagrid controls and tweaking the Datagrid to
suit my needs (columnheader, columnwidth, etc.)

Now I'm using vb.net, and I'm tryint to do the same
thing binding a Datareader to the Datagrid. If I bind
the Datagrid directly to the Datareader it works fine.

But if I:

myDataGrid.AutoGenerateColumns = False

Dim myColumn as BoundColumn
myColumn = New BoundColumn

myColumn.HeaderText = "Number"
myColumn.DataField = DataReader(0)

myDataGrid.Columns.Add(myColumn)

myDataGrid.DataSource = DataReader
myDataGrid.DataBind()

I get a column with the proper header, but no data
appears in the DataGrid. I realize that I should leave well
enough alone and let AutoGenerateColumns do it's job,
but I'd like to have a little more control.

Am I missing the boat here?

TIA,

BC
 
M

Marina

It looks like the data field is being set to the value of the column at
position 0. So the contents of that column - instead of the name of that
column. To do this, you also probably had to do a .Read, so you are already
on the first record, and that record would not be displayed in the grid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top