Solved

Checking for empty set -- Oracle

Posted on 2006-06-13
1
444 Views
Last Modified: 2012-05-05
Hi -

I'm having a little bit of a problem.
When the page loads a query is ran and populates the fields depending on the user name.
Sometimes it seems like the query doesn't even run.

I want to check to see if it is an empty set,
Then lblEmptySet.Text = "Empty"

Here is my code:

string mySelectQuery = "SELECT EMPLOYEE_NUMBER,START_DATE FROM BMDW_EMPLOYEE WHERE LAST_NAME ='" + lblLastName.Text.ToUpper() + "'";
                    string myConnString = "data source=*****;user id=******; password=******";
                    OracleConnection myDBConnection = new OracleConnection(myConnString);

                    OracleDataAdapter myAdapter = new OracleDataAdapter(mySelectQuery, myDBConnection);
                    myDBConnection.Open();
                    OracleDataReader myReader = myAdapter.SelectCommand.ExecuteReader();
                   
                    while (myReader.Read())
                    {
                        string EmpID = myReader["EMPLOYEE_NUMBER"].ToString();
                        lblEmpNum.Text = EmpID;

                        string strHireDate = myReader["START_DATE"].ToString();
                        txtHireDate.Text = strHireDate;
                    }

                    myDBConnection.Close();
0
Comment
Question by:JordanBlackler
1 Comment
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 16895880
Hi, try checking the HasRows property of the data reader:

...
if (myReader.HasRows)
{
      while (myReader.Read())
      {
           string EmpID = myReader["EMPLOYEE_NUMBER"].ToString();
           lblEmpNum.Text = EmpID;

           string strHireDate = myReader["START_DATE"].ToString();
           txtHireDate.Text = strHireDate;
       }
}
else
{
       lblEmptySet.Text = "Empty";
}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now