Trouble getting row count from DataReader

Discussion in 'ASP .Net' started by Kevin, Dec 18, 2003.

  1. Kevin

    Kevin Guest

    I am using the DataReader to populate an ASP table dynamically. I would
    like to set the tables "visible" property based on the the data from my
    query. For example, if I have at least one row of data, I will set visible
    to true, otherwise, false.

    How get I find out if I have at least one row of data? The code below is
    from the CodeBehind of my asp form.

    *****************************
    OracleConnection conn = new OracleConnection(ConnectionString);
    OracleCommand cmd = new OracleCommand("select * from customer where name =
    'BOB', conn);
    try
    {
    conn.Open();
    IDataReader reader = cmd.ExecuteReader();
    _grid.DataSource = reader;
    _grid.DataBind();
    }
    finally
    {
    conn.Dispose();
    }
    *****************************

    Thanks,
    Kevin
     
    Kevin, Dec 18, 2003
    #1
    1. Advertising

  2. Kevin

    Jerry Boone Guest

    I think your only option on a DataReader is to use the .Read property. It
    returns false if it can't produce a record.

    Otherwise, a dataset is necessary to get the actual record count.

    --
    Jerry Boone
    Analytical Technologies, Inc.
    http://www.antech.biz


    "Kevin" <kevin@spammers_die.com> wrote in message
    news:...
    > I am using the DataReader to populate an ASP table dynamically. I would
    > like to set the tables "visible" property based on the the data from my
    > query. For example, if I have at least one row of data, I will set

    visible
    > to true, otherwise, false.
    >
    > How get I find out if I have at least one row of data? The code below is
    > from the CodeBehind of my asp form.
    >
    > *****************************
    > OracleConnection conn = new OracleConnection(ConnectionString);
    > OracleCommand cmd = new OracleCommand("select * from customer where name =
    > 'BOB', conn);
    > try
    > {
    > conn.Open();
    > IDataReader reader = cmd.ExecuteReader();
    > _grid.DataSource = reader;
    > _grid.DataBind();
    > }
    > finally
    > {
    > conn.Dispose();
    > }
    > *****************************
    >
    > Thanks,
    > Kevin
    >
    >
     
    Jerry Boone, Dec 18, 2003
    #2
    1. Advertising

  3. Kevin

    Kevin Guest

    Thanks Jerry, that was exactly what I needed.

    Kevin



    "Jerry Boone" <> wrote in message
    news:mkmEb.1432$...
    > I think your only option on a DataReader is to use the .Read property. It
    > returns false if it can't produce a record.
    >
    > Otherwise, a dataset is necessary to get the actual record count.
    >
    > --
    > Jerry Boone
    > Analytical Technologies, Inc.
    > http://www.antech.biz
    >
    >
    > "Kevin" <kevin@spammers_die.com> wrote in message
    > news:...
    > > I am using the DataReader to populate an ASP table dynamically. I would
    > > like to set the tables "visible" property based on the the data from my
    > > query. For example, if I have at least one row of data, I will set

    > visible
    > > to true, otherwise, false.
    > >
    > > How get I find out if I have at least one row of data? The code below

    is
    > > from the CodeBehind of my asp form.
    > >
    > > *****************************
    > > OracleConnection conn = new OracleConnection(ConnectionString);
    > > OracleCommand cmd = new OracleCommand("select * from customer where name

    =
    > > 'BOB', conn);
    > > try
    > > {
    > > conn.Open();
    > > IDataReader reader = cmd.ExecuteReader();
    > > _grid.DataSource = reader;
    > > _grid.DataBind();
    > > }
    > > finally
    > > {
    > > conn.Dispose();
    > > }
    > > *****************************
    > >
    > > Thanks,
    > > Kevin
    > >
    > >

    >
    >
     
    Kevin, Dec 18, 2003
    #3
    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. Derek LaZard

    Re: Abt Datareader Count

    Derek LaZard, Jul 8, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,744
    Derek LaZard
    Jul 8, 2003
  2. Bernie V

    trouble with DataReader

    Bernie V, Feb 11, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    465
    Dilip Krishnan
    Feb 11, 2004
  3. JustinCarmony
    Replies:
    1
    Views:
    439
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Apr 2, 2007
  4. David C

    DataReader record count

    David C, Sep 30, 2009, in forum: ASP .Net
    Replies:
    7
    Views:
    1,078
    Gregory A. Beamer
    Sep 30, 2009
  5. D
    Replies:
    0
    Views:
    220
Loading...

Share This Page