473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

data reader

121 100+
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
Apr 14 '08 #1
3 1786
balame2004
142 100+
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
Apr 14 '08 #2
Curtis Rutland
3,256 Expert 2GB
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 OleDbDataAdapter instead. use it like this:
Expand|Select|Wrap|Line Numbers
  1. //this is c# code, but the VB.NET is similar.
  2. string sql = "select * from whateverTable";
  3. string connStr = "connection string goes here";
  4. OleDbConnection conn = new OleDbConnection(connStr);
  5. OleDbDataAdapter adapt = new OleDbDataAdapter(sql,conn);
  6. DataSet ds = new DataSet();
  7. adapt.Fill(ds,"table_name");
  8. //now you have access to the whole query's recordset in a DataTable!
  9. //here's how you get to it.
  10. DataTable table = ds.Tables["table_name"];
  11.  
Now you can manipulate your whole recordset inside that DataTable. Also, you can check the total # of records like this:

Expand|Select|Wrap|Line Numbers
  1. table.Rows.Count;
  2.  
Apr 14 '08 #3
balame2004
142 100+
I like to use an OleDbDataAdapter instead. use it like this:
Expand|Select|Wrap|Line Numbers
  1. //this is c# code, but the VB.NET is similar.
  2. string sql = "select * from whateverTable";
  3. string connStr = "connection string goes here";
  4. OleDbConnection conn = new OleDbConnection(connStr);
  5. OleDbDataAdapter adapt = new OleDbDataAdapter(sql,conn);
  6. DataSet ds = new DataSet();
  7. adapt.Fill(ds,"table_name");
  8. //now you have access to the whole query's recordset in a DataTable!
  9. //here's how you get to it.
  10. DataTable table = ds.Tables["table_name"];
  11.  
Now you can manipulate your whole recordset inside that DataTable. Also, you can check the total # of records like this:

Expand|Select|Wrap|Line Numbers
  1. table.Rows.Count;
  2.  

Hello,

DataTable could be valuable solution for your problem.

Cheers,
Balaji U
Apr 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mike L | last post by:
I tried a sample of code in MSDN magazine, but now I'm stuck. What code has the best performance to populate a Data Grid with a SP? Below is the code I have, which might be completing the wrong...
2
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row...
4
by: Ram | last post by:
I am using ADO.Net data reader to retrieve data from main frame. I am getting timestamp which is 26 (yyyy-mm-dd hh- mm-ss.123456) bytes as sqltimestamp data type. I am using data reader to...
2
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate>...
0
by: Crazy Cat | last post by:
In the following code I retrieve data from a stored procedure that returns multiple resultsets (the results of the stored procedure have been stored in a datareader called reader). On each...
6
by: Jim Heavey | last post by:
I am new to SqlServer, have been using Oracle in a prior life. I have written a very simple stored procedure in SQL Server and it (the query) looks like the following... Select AD_ID,...
1
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
0
by: bill | last post by:
Can someone please show me what to do with this to show the data in a dataGrid for example? I'm not really sure what to do with it. I'm used to Vb6. Dim Con = New...
1
by: =?Utf-8?B?SkI=?= | last post by:
Hello My pgm1 (User Interface Level) passes an empty ArrayList to pgm2 (Business Logic Level). pgm2 then calls pgm3 (Data Access Level) to populate the ArrayList. Question1: When pgm2 gets...
1
by: dotnetnovice | last post by:
Hi everybody... I want to show data in the data gridview placed in my form after getting data from my data access layer class through a class... Here is my code in the data access layer class....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.