?
Solved

Check is datareader has rows in .net 2.0 c#

Posted on 2007-04-02
3
Medium Priority
?
1,676 Views
Last Modified: 2013-11-07
       public static CustomerListGetList()
        {
            CustomerList tempList = null;
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand("spTest");
            dbCommand.CommandType = CommandType.StoredProcedure;

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {  
                  //how can i check if the datareader has rows here?

                tempList = new CustomerList();
                while (dataReader.Read())
                {
                    tempList.Add(FillDataRecord(dataReader));
                }                
                dataReader.Close();
            }
            return tempList;
        }
0
Comment
Question by:mugsey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18837716
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {  
                  //how can i check if the datareader has rows here?
                 if (dataReader.HasRows())
 . ...

0
 

Author Comment

by:mugsey
ID: 18838508
it does not have an option for this
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 18838993
I see, you used the DataFactory's that returns a IDataReader that does not expose that property


 public static CustomerListGetList()
        {
            CustomerList tempList = null;
            int intRows = 0;

            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand("spTest");
            dbCommand.CommandType = CommandType.StoredProcedure;

            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {  
                tempList = new CustomerList();

                while (dataReader.Read())
                {
                    intRows ++;
                    tempList.Add(FillDataRecord(dataReader));
                }                
                dataReader.Close();
            }

            //check if the datareader has had rows here?
            if (intRows == 0)
            { // had no rows ... }

            return tempList;
        }
Authored by: mugsey
0

Featured Post

Cloud Training Guides

FREE GUIDES: In-depth and hand-crafted Linux, AWS, OpenStack, DevOps, Azure, and Cloud training guides created by Linux Academy instructors and the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question