Count problem with dataset

  • Thread starter Thread starter al
  • Start date Start date
A

al

The following code tries to count the record in the dataset but fails
when I wrap it up in a if statement. Please help, go easy on any
stupidity because I am new to dotnet. The Data is gathered from a
Paradox table and that part appears to work because the dataset
contains the record i require.

myInt = DsDataSet.Tables("PXResult").Rows.Count
'the above line makes myint equal 1
If myInt > 0 Then
MsgBox(CType(myInt, String) & " with the first called
" & DsDataSet.Tables("PXResult").Rows(0).Item("FirstName"),
MsgBoxStyle.OKOnly)
End If

If DsDataSet.Tables("PXResults").Rows.Count = 1 Then
'the above line crashes

I get the following error:-
An unhandled exception of type 'System.NullReferenceException'
occurred in Subcon.exe

Additional information: Object reference not set to an instance of an
object.

Many thanks

Al
 
Hi Al,

Where it crashes, because this would mean the dataset is totally empty and
it should already crash on the first row.

The references are set as
Dataset and than datatable, so you can have a
If dataset Is Nothing ' there is no dataset and you can have
If dataset.tables(0) Is Nothing ' there is no reference to a datatable in
the dataset.

I hope this helps?

Cor
 
Thanks thats brill I better go back to the 1000 odd pages of .net reading i
been doing.

Al
 
Back
Top