Solved

Checking for empty set -- Oracle

Posted on 2006-06-13
1
450 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
[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
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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