473,770 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Con nectionString = Application("co nnect")
oConnection.Ope n()

sql = "SELECT * from table"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
...

This works perfect, but how to use dtreader when the datasource is defined
in the aspx file like this?
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$
ConnectionStrin gs:cat %>"
SelectCommand=" SELECT * table"></asp:SqlDataSour ce>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqldat asource1.??? 'there is no ExecuteReader available in
the list
Thanks for helping.
Casper


Feb 6 '07 #1
4 11408
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******** ******@TK2MSFTN GP06.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.Con nectionString = Application("co nnect")
oConnection.Ope n()

sql = "SELECT * from table"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
...

This works perfect, but how to use dtreader when the datasource is defined
in the aspx file like this?
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:cat %>"
SelectCommand=" SELECT * table"></asp:SqlDataSour ce>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqldat asource1.??? '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.orgsch reef in
bericht news:uC******** ******@TK2MSFTN GP03.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******** ******@TK2MSFTN GP06.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.Con nectionString = Application("co nnect")
oConnection.Ope n()

sql = "SELECT * from table"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
...

This works perfect, but how to use dtreader when the datasource is
defined in the aspx file like this?
<asp:SqlDataSo urce ID="SqlDataSour ce1" runat="server"
ConnectionStri ng="<%$ ConnectionStrin gs:cat %>"
SelectCommand=" SELECT * table"></asp:SqlDataSour ce>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqlda tasource1.??? '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.DataS ource=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******** ********@TK2MSF TNGP03.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.orgsch reef in
bericht news:uC******** ******@TK2MSFTN GP03.phx.gbl...
>You can set the DataSourceMode attribute to DataReader and the
sqldatasourc e 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******* *******@TK2MSFT NGP06.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.Con nectionString = Application("co nnect")
oConnection.Ope n()

sql = "SELECT * from table"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
...

This works perfect, but how to use dtreader when the datasource is
defined in the aspx file like this?
<asp:SqlDataS ource ID="SqlDataSour ce1" runat="server"
ConnectionStr ing="<%$ ConnectionStrin gs:cat %>"
SelectCommand=" SELECT * table"></asp:SqlDataSour ce>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sqld atasource1.??? 'there is no ExecuteReader available
in the list
Thanks for helping.
Casper




Feb 7 '07 #4
Thanks

"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgsch reef in
bericht news:eW******** ********@TK2MSF TNGP03.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.DataS ource=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******** ********@TK2MSF TNGP03.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.orgsch reef in
bericht news:uC******** ******@TK2MSFTN GP03.phx.gbl...
>>You can set the DataSourceMode attribute to DataReader and the
sqldatasour ce 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****** ********@TK2MSF TNGP06.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.Con nectionString = Application("co nnect")
oConnection.Ope n()

sql = "SELECT * from table"
comd = New OleDbCommand(sq l, oConnection)
dtreader = comd.ExecuteRea der
...

This works perfect, but how to use dtreader when the datasource is
defined in the aspx file like this?
<asp:SqlData Source ID="SqlDataSour ce1" runat="server"
ConnectionSt ring="<%$ ConnectionStrin gs:cat %>"
SelectCommand=" SELECT * table"></asp:SqlDataSour ce>

I tried this in code-behind:
Dim dtreader As OleDbDataReader
dtreader=sql datasource1.??? '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
5073
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 having problems making this work. Inside connectionStrings I added my name, provider and connectionString but for some reason SqlDataSource is trying to use System.Data.SqlClient even if my provider is different.
1
1896
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
12734
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 on how to handle different tasks programmatically such as selects, updates, sorting of data etc. in code behind if I prefer to set all Gridview and Sqldatasource properties etc. in code behind rather than in the aspx file.
1
8434
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 %>" SelectCommand="SELECT ShoppingCoupons.*, CouponCode AS Expr1 FROM ShoppingCoupons WHERE (CouponCode = @CouponCode)"> <SelectParameters> <asp:ControlParameter ControlID="txtCouponCode" DefaultValue="000"
4
5381
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 connectionStrings defined in my web.config file, one for the development db and another for the production db. When I publish my app to the hosting site, I rename the two connection strings so that the production string will be the active string in the...
2
19794
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 <selectParameters> but i don't know which elements are needed and how... This is my aspx file: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mydb.mdb"
5
7688
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, the compiler believes an SQL db is being accessed ("An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does...
2
1998
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 several items. The reason I'm wondering if I should use an SqlDataSource object is overhead. For example, prior to learning about the sqlDataSource I would just code the ado.net procedure myself. For example, create connection object, create and...
2
6752
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 TestNo, AcceptDate, status FROM TestForm WHERE (AcceptDate BETWEEN @prAcceptDate AND @prAcceptDateEnd)" ProviderName="<%$ ConnectionStrings:GConnectionStringA.ProviderName %>" EnableViewState="False">
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10099
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10037
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8931
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.