?
Solved

Checking for empty set -- Oracle

Posted on 2006-06-13
1
Medium Priority
?
452 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

771 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