[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Check is datareader has rows in .net 2.0 c#

Posted on 2007-04-02
3
Medium Priority
?
1,681 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

656 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