how to use datareader with sqldatasource defined in aspx file?

Discussion in 'ASP .Net' started by Casper, Feb 6, 2007.

  1. Casper

    Casper Guest

    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
    Casper, Feb 6, 2007
    #1
    1. Advertising

  2. 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:...
    > 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, Feb 6, 2007
    #2
    1. Advertising

  3. Casper

    Casper Guest

    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" <> schreef in
    bericht news:...
    > 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:...
    >> 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
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >
    Casper, Feb 6, 2007
    #3
  4. 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:%...
    > 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" <> schreef in
    > bericht news:...
    >> 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:...
    >>> 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, Feb 7, 2007
    #4
  5. Casper

    Casper Guest

    Thanks

    "Eliyahu Goldin" <> schreef in
    bericht news:eWqKn%...
    > 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:%...
    >> 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" <> schreef in
    >> bericht news:...
    >>> 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:...
    >>>> 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
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
    Casper, Feb 7, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marty

    SqlDataSource DataReader in Code

    Marty, Oct 25, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    949
    Marty
    Oct 25, 2006
  2. Oodini
    Replies:
    1
    Views:
    1,762
    Keith Thompson
    Sep 27, 2005
  3. slY
    Replies:
    3
    Views:
    1,987
  4. JohnE
    Replies:
    3
    Views:
    1,269
    JohnE
    Jan 31, 2010
  5. Casper
    Replies:
    4
    Views:
    791
    Casper
    Feb 7, 2007
Loading...

Share This Page