Datareader binding to datagrid not working

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

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 had written out from my web
apps.

I can get my DataReader to read my data fine. But I wanted to use a
DataGrid, but it is apparently completely different????

I can do:

DataGrid1.DataSource = dbReader
DataGrid1.DataBind()

I get an error saying something about: "Complex DataBinding accepts as a
data source either an IList or an IListSource".

There also doesn't seem to be a DataBind() method to this DataGrid?

Why doesn't it work?

Can I not make a standalone program using the same techniques as I do in my
Web pages (asp.net)?

Thanks,

Tom
 
tshad said:
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 had written out from my web
apps.

I can get my DataReader to read my data fine. But I wanted to use a
DataGrid, but it is apparently completely different????

I can do:

DataGrid1.DataSource = dbReader
DataGrid1.DataBind()

I get an error saying something about: "Complex DataBinding accepts as a
data source either an IList or an IListSource".

There also doesn't seem to be a DataBind() method to this DataGrid?

Why doesn't it work?

Can I not make a standalone program using the same techniques as I do in my
Web pages (asp.net)?

Thanks,

Tom

You can not bind a datareader to a datasource. You will need to either
load it into a datatable by looping through the datareader or use a
dataadapter to do what you want.

chris
 
I Don't Like Spam said:
You can not bind a datareader to a datasource. You will need to either
load it into a datatable by looping through the datareader or use a
dataadapter to do what you want.
Is that something that something that you can only do in a web page? I
databind datareaders to a datagrid all the time?

Tom
 
Thsad,

Although that the grid have in net 1.x for ASPNET and Windowforms the same
name (DataGrid), do they act completely different (in Net 2.0 the new Grids
have different names, it is probably not for nothing that this confusing
thing is now done well).

However there are some things the same. The ASPNET datagrid accepts a
DataReader, a Datatable and a DataSet. A windowform DataGrid (in theory more
however in fact) only the last two.

To see a lot of samples about the datagrid can you look on our (non
commercial) website.

http://www.vb-tips.com/default.aspx

I hope this helps,

Cor
 
Back
Top