NullReferenceException...why

  • Thread starter Thread starter Chuck Hecht
  • Start date Start date
C

Chuck Hecht

I am getting the "NullReferenceException" error on this line

foundRow = dsScannerdata.Tables("dtReceivePdai").Rows.Find(mykey)


in the following code.

All of the values in the mykey field are unique and there are not blank
records

Any help is appreicated!!!!!!!

*******code to find the record in the table********

Dim mykey As String = gMykey.ToString

Dim foundRow As DataRow

foundRow = dsScannerdata.Tables("dtReceivePdai").Rows.Find(mykey)

If foundRow IsNot Nothing Then

MsgBox(foundRow(1).ToString())

Else

MsgBox("A row with the primary key of " & mykey & " could not be found")

End If



mykey is the primary key in the table receivepdai

*******code for primary key field********

Dim dcmykey(1) As DataColumn

dcmykey(0) = New DataColumn("mykey", System.Type.GetType("System.String"))

dtReceivePdai.Columns.Add(dcmykey(0))

dtReceivePdai.PrimaryKey = dcmykey
 
Most likley because there's no table called "dtReceivePdai" in this DataSet.
Or may be there's no dsScannerdata.
You should use debugger to figure out which object you actually don't have.

--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
Back
Top