Checking for a null recordset return - C# - SQL

Hello all.  I need to run a check if I return a record from a table based on criteria.  Then I need to say if not rs.EOF etc.  How do I handle that in C#?  Thanks all
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:

use xxxDataReader and check the HasRows Property

for example

                  SqlCommand cmd = new SqlCommand("Select * from employees where EmployeeID = 10",con);
                  SqlDataReader dr;
                  dr = cmd.ExecuteReader();

                  if (dr.HasRows)
                        MessageBox.Show(" Table has records");
                        MessageBox.Show("No data found");

if you want to itrate the records use

               while (dr.Read())



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
There are not recordsets in C#.
There are datasets and there are datatables.
Datasets can contain DataTables or DataTables can be stand alone.

you can check to see if a datatable is empty like this.

DataTable dtDataTable = new DataTable("dtDataTable");
dtDataTable = ###Some code to fill the table with data.###

//To check for NULL
if (dtDataTable == null)

//To check for NOT NULL
if (!(dtDataTable == null))  // or (dtDataTable != null)

//To check for empty table
if (dtDataTable.Rows.Count > 0)

//To scroll through table until EOF
foreach (DataRow drDataRow in dtDataTable.Rows)
     MessageBox.Show(this, drDataRow["ColumnName"].ToString());

If a dataset is used just replace 'dtDataTable' with 'dsDataSet.Tables["dtDataTable"]'.

I think thats it.
Hope I helped alittle.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.