473,400 Members | 2,145 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,400 software developers and data experts.

how to use datareader with sqldatasource defined in aspx file?

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


Feb 6 '07 #1
4 11383
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" <s@sdwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
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


Feb 6 '07 #2
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" <RE**************************@mMvVpPsS.orgschree f in
bericht news:uC**************@TK2MSFTNGP03.phx.gbl...
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" <s@sdwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
>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



Feb 6 '07 #3
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" <s@sdwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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" <RE**************************@mMvVpPsS.orgschree f in
bericht news:uC**************@TK2MSFTNGP03.phx.gbl...
>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" <s@sdwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
>>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




Feb 7 '07 #4
Thanks

"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgschree f in
bericht news:eW****************@TK2MSFTNGP03.phx.gbl...
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" <s@sdwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>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" <RE**************************@mMvVpPsS.orgschree f in
bericht news:uC**************@TK2MSFTNGP03.phx.gbl...
>>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" <s@sdwrote in message
news:eA**************@TK2MSFTNGP06.phx.gbl...
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






Feb 7 '07 #5

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

Similar topics

3
by: zapov | last post by:
Hi! Did anyone successfully managed to use some custom ADO.NET provider with SqlDataSource? I'd like to connect to some other database than MSSQL (like MySQL, Firebird or PostgreSQL) but I'm...
1
by: staeri | last post by:
Hello! I would like to set the SqlDataSource in the code behind file and not to have it in the aspx file. How can I do that? Regards, Staeri
3
by: Dorte | last post by:
Hi, Could someone help me with a couple of links to SqlDatasource documentation on how to use the Gridview and SqlDatasource components in code behind? Basically I'm missing some documentation...
1
by: VB Programmer | last post by:
Asp.net 2.0... I have an SqlDataSource on my aspx form. It's defined as... <asp:SqlDataSource ID="sdsCoupons" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"...
4
by: Matt Colegrove | last post by:
I'm working on a web app that is published to a hosting service. I'm developing it on my local PC with VS 2005 and SQL Express. The hosting service DB is SQL Server 2000. I have two...
2
by: phil | last post by:
Hi, I want to put a recordset in a gridview but i don't know how to pass the value of the variable in the 'where' statement. The value of the variable is set in the code-behind. i added a tag...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
2
by: djc | last post by:
1) I am wondering if I should be using an sqlDataSource object for my particular scenario. I need to loop through a listbox and perform an INSERT sql operation for each item. Could be a few or...
2
by: Jason Huang | last post by:
Hi, Here is my SqlDataSource in my C#.2.0 aspx file: <asp:SqlDataSource ID="SqlDataSourceA" runat="server" ConnectionString="<%$ ConnectionStrings:GConnectionStringA %>" SelectCommand="SELECT...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.