Count problem with dataset

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
 
C

Cor

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
 
N

news.mersinet.co.uk

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

Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top