how to use datareader with sqldatasource defined in aspx file?

  • Thread starter Thread starter Casper
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top