how to use datareader with sqldatasource defined in aspx file?

C

Casper

Hi,

i know how to use datareader in code-behind, e.g. like this:

Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

oConnection = New OleDbConnection()
oConnection.ConnectionString = Application("connect")
oConnection.Open()

sql = "SELECT * from table"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
...

This works perfect, but how to use dtreader when the datasource is defined
in the aspx file like this?
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:cat %>"
SelectCommand="SELECT * table"></asp:SqlDataSource>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqldatasource1.??? 'there is no ExecuteReader available in
the list


Thanks for helping.
Casper
 
C

Casper

Thanks for replying.
I did it in tthe aspx file but how can i link the sqlsource2 defined in the
aspx file to the data reader defined in the code-behind? I don't want to
redefine all the sql statement and parameter in the code-behind. That's my
problem.




Eliyahu Goldin said:
You can set the DataSourceMode attribute to DataReader and the
sqldatasource will be using a datareader automatically. Is that what you
are after?


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Casper said:
Hi,

i know how to use datareader in code-behind, e.g. like this:

Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

oConnection = New OleDbConnection()
oConnection.ConnectionString = Application("connect")
oConnection.Open()

sql = "SELECT * from table"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
...

This works perfect, but how to use dtreader when the datasource is
defined in the aspx file like this?
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:cat %>"
SelectCommand="SELECT * table"></asp:SqlDataSource>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqldatasource1.??? 'there is no ExecuteReader available
in the list


Thanks for helping.
Casper
 
E

Eliyahu Goldin

If you already have the datareader, there is no reason to use sqldatasource.
Instead of databinding with DataSourceID, do with DataSource="<%# myReader
%>" in the markup or myControl.DataSource=myReader; codebhind.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Casper said:
Thanks for replying.
I did it in tthe aspx file but how can i link the sqlsource2 defined in
the aspx file to the data reader defined in the code-behind? I don't want
to redefine all the sql statement and parameter in the code-behind. That's
my problem.




Eliyahu Goldin said:
You can set the DataSourceMode attribute to DataReader and the
sqldatasource will be using a datareader automatically. Is that what you
are after?


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Casper said:
Hi,

i know how to use datareader in code-behind, e.g. like this:

Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

oConnection = New OleDbConnection()
oConnection.ConnectionString = Application("connect")
oConnection.Open()

sql = "SELECT * from table"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
...

This works perfect, but how to use dtreader when the datasource is
defined in the aspx file like this?
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:cat %>"
SelectCommand="SELECT * table"></asp:SqlDataSource>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqldatasource1.??? 'there is no ExecuteReader available
in the list


Thanks for helping.
Casper
 
C

Casper

Thanks

Eliyahu Goldin said:
If you already have the datareader, there is no reason to use
sqldatasource. Instead of databinding with DataSourceID, do with
DataSource="<%# myReader %>" in the markup or
myControl.DataSource=myReader; codebhind.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Casper said:
Thanks for replying.
I did it in tthe aspx file but how can i link the sqlsource2 defined in
the aspx file to the data reader defined in the code-behind? I don't want
to redefine all the sql statement and parameter in the code-behind.
That's my problem.




Eliyahu Goldin said:
You can set the DataSourceMode attribute to DataReader and the
sqldatasource will be using a datareader automatically. Is that what you
are after?


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Hi,

i know how to use datareader in code-behind, e.g. like this:

Dim oConnection As OleDbConnection
Dim comd As OleDbCommand
Dim dtreader As OleDbDataReader

oConnection = New OleDbConnection()
oConnection.ConnectionString = Application("connect")
oConnection.Open()

sql = "SELECT * from table"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
...

This works perfect, but how to use dtreader when the datasource is
defined in the aspx file like this?
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:cat %>"
SelectCommand="SELECT * table"></asp:SqlDataSource>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqldatasource1.??? 'there is no ExecuteReader available
in the list


Thanks for helping.
Casper
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top