Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeshbr
jeshbr

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)
{
     //code
}

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

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

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

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


I think thats it.
Hope I helped alittle.