Solved

Checking for empty set -- Oracle

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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