Groups | Blog | Home
all groups > asp.net datagrid control > february 2007 >

asp.net datagrid control : how to use datareader with sqldatasource defined in aspx file?


Casper
2/6/2007 11:06:18 AM
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





Eliyahu Goldin
2/6/2007 12:20:43 PM
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


[quoted text, click to view]

Casper
2/6/2007 7:04:01 PM
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" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.org> schreef in
bericht news:uCqzhjdSHHA.2188@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

Eliyahu Goldin
2/7/2007 10:10:03 AM
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


[quoted text, click to view]

Casper
2/7/2007 10:52:40 AM
Thanks

"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@mMvVpPsS.org> schreef in
bericht news:eWqKn%23oSHHA.3592@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button