data reader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • charvi
    New Member
    • May 2007
    • 121

    data reader

    i hae a ole data reader which contains records extracted from Query.how can i check for end of file in data reader.and i want to know the number of records present in data reader
    thanks in advance
  • balame2004
    New Member
    • Mar 2008
    • 142

    #2
    Originally posted by charvi
    i hae a ole data reader which contains records extracted from Query.how can i check for end of file in data reader.and i want to know the number of records present in data reader
    thanks in advance
    1.DataReader provides only way to read data in forward only and read only mode. So you have to read each record one by one by using Read() method of data reader and you have to predict that there is no more record once Read method returns false and now current record would be the last record.

    2.There is no property/method to know no.of rows in a datareader. You need to run a for loop to read data from datareader and increment an index variable unless it reaches end of datareader(when Read method of DataReader returns false).


    Cheers,
    Balaji U

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Originally posted by charvi
      i hae a ole data reader which contains records extracted from Query.how can i check for end of file in data reader.and i want to know the number of records present in data reader
      thanks in advance
      I like to use an OleDbDataAdapte r instead. use it like this:
      [CODE=cpp]
      //this is c# code, but the VB.NET is similar.
      string sql = "select * from whateverTable";
      string connStr = "connection string goes here";
      OleDbConnection conn = new OleDbConnection (connStr);
      OleDbDataAdapte r adapt = new OleDbDataAdapte r(sql,conn);
      DataSet ds = new DataSet();
      adapt.Fill(ds," table_name");
      //now you have access to the whole query's recordset in a DataTable!
      //here's how you get to it.
      DataTable table = ds.Tables["table_name "];
      [/CODE]

      Now you can manipulate your whole recordset inside that DataTable. Also, you can check the total # of records like this:

      [CODE=cpp]
      table.Rows.Coun t;
      [/CODE]

      Comment

      • balame2004
        New Member
        • Mar 2008
        • 142

        #4
        Originally posted by insertAlias
        I like to use an OleDbDataAdapte r instead. use it like this:
        [CODE=cpp]
        //this is c# code, but the VB.NET is similar.
        string sql = "select * from whateverTable";
        string connStr = "connection string goes here";
        OleDbConnection conn = new OleDbConnection (connStr);
        OleDbDataAdapte r adapt = new OleDbDataAdapte r(sql,conn);
        DataSet ds = new DataSet();
        adapt.Fill(ds," table_name");
        //now you have access to the whole query's recordset in a DataTable!
        //here's how you get to it.
        DataTable table = ds.Tables["table_name "];
        [/CODE]

        Now you can manipulate your whole recordset inside that DataTable. Also, you can check the total # of records like this:

        [CODE=cpp]
        table.Rows.Coun t;
        [/CODE]

        Hello,

        DataTable could be valuable solution for your problem.

        Cheers,
        Balaji U

        Comment

        Working...