473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Datareader to Datagrid

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

Nov 18 '05 #1
1 1544
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.

"BC" <bc***********@speakeasy.org> wrote in message
news:xe********************@speakeasy.net...

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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Al | last post by:
in order to implement sorting, paging in a datagrid, can I have the datasource of the datagrid a datareader or it must be a dataset then I create a dataview and make it a datasource of the...
6
by: Ricardo Luceac | last post by:
Hi... My program make a select to an table and return the results to a datagrid, it's all ok with dataset, but in large tables it needs to get the entire table to show in datagrid and sometimes...
5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
2
by: Wayne Wengert | last post by:
I am trying to learn to use VS NET and codebehind for asp.net apps and I've run into a problem trying to use a datareader. I created a new webform and inserted and configured a sqlconnection and...
12
by: Thomas Scheiderich | last post by:
I have 2 dropdowns that are exactly the same and I don't want to re-read for each. Is there a way to do something like below where I read the data, bind to depCity1 and then bind to destCity2. ...
7
by: Bart Schelkens | last post by:
Hi, I have 2 more questions : 1. Can I fill a datagrid by using a DataReader or does it have to be a DataSet or a DataView? 2. In my datagrid I need to display two images and one of does...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
4
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view...
3
by: tshad | last post by:
I am using VS 2003 and trying to build a standalone application. I have been writing all my asp.net work using DW and am just now trying to build a application that will read some of the tables I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.