Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > how to use datareader with sqldatasource defined in aspx file?

Reply
Thread Tools

how to use datareader with sqldatasource defined in aspx file?

 
 
Casper
Guest
Posts: n/a
 
      02-06-2007
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






 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-06-2007
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@sd> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Casper
Guest
Posts: n/a
 
      02-06-2007
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" <(E-Mail Removed)> schreef in
bericht news:(E-Mail Removed)...
> 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@sd> wrote in message
> news:(E-Mail Removed)...
>> 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
>>
>>
>>
>>
>>
>>

>
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      02-07-2007
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@sd> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> schreef in
> bericht news:(E-Mail Removed)...
>> 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@sd> wrote in message
>> news:(E-Mail Removed)...
>>> 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
>>>
>>>
>>>
>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Casper
Guest
Posts: n/a
 
      02-07-2007
Thanks

"Eliyahu Goldin" <(E-Mail Removed)> schreef in
bericht news:eWqKn%(E-Mail Removed)...
> 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@sd> wrote in message
> news:%(E-Mail Removed)...
>> 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" <(E-Mail Removed)> schreef in
>> bericht news:(E-Mail Removed)...
>>> 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@sd> wrote in message
>>> news:(E-Mail Removed)...
>>>> 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
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
ReportView + SQLDataSource (dinamically defined) slY ASP .Net 3 01-15-2010 05:05 PM
how to use datareader with sqldatasource defined in aspx file? Casper ASP .Net Datagrid Control 4 02-07-2007 09:52 AM
SqlDataSource DataReader in Code Marty ASP .Net 0 10-25-2006 07:24 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM



Advertisments