Object reference not set to an instance of an object

Y

Yogs

Hi All,



I have an intermittent problem with an SQLDataAdapter.Fill command. Every
now and then the system returns an "Object reference not set to an instance
of an object" right after filling the Address table.



Public Sub GetProfileTables(ByVal strSQL As String)


Dim cnn As New SqlConnection("Server=localhost; Database=myDatabase;
UID=user; PWD=password;")

_profileSet = New DataSet("Profile")
cnn.Open()



'Get the profile tables information

' The SQL statement would be something like SELECT * FROM vwProfile
WHERE profile_key = 1110201

' where the profile key basically is different depending on the
record being viewed.

Dim daProfile As New SqlDataAdapter(strSQL, cnn)
daProfile.Fill(_profileSet, "Profile")
_profileView = _profileSet.Tables("Profile").DefaultView



'Get the profile addresses
strSQL = "select * from address where profile_key = " &
_profileView(0)("profile_key")
daProfile.SelectCommand = New SqlCommand(strSQL, cnn)
daProfile.Fill(_profileSet, "Address")



'Define the parent and child columns
Dim parentCol, childCol As DataColumn
parentCol = _profileSet.Tables("Profile").Columns("profile_key")
childCol = _profileSet.Tables("Address").Columns("profile_key") '
**THIS IS WHERE THE ERROR OCCURS**



'Define the relationship of the data
Dim drProfile As DataRelation
drProfile = New DataRelation("ProfileAddress", parentCol, childCol)
_profileSet.Relations.Add(drProfile)



cnnITT.Close()
End Sub



Any suggestions?



Thanks

Ryan
 
R

Rajesh Patel

can you check whether your fill command add "address" datatable into
_profileset dataset?

Regards,

Rajesh Patel
 
Y

Yogs

Hi Rajesh,

If I do add in a check to see if it was added, what do I do if it wasn't.
The application expects the "address" table to be there. I was also under
the understanding that the fill command adds the table to the dataset
everytime even if the number of records is 0. Is that incorrect?

Thanks,
Ryan
 
R

Rajesh Patel

If it is not there, you can add table manually.

I believe your first table it creates automatically from name given in the
declaration of the dataset. that is profile.
so, add "address" table manually. you can actually see how vs.net add
"profile" table in windows generated code.

Regards,

Rajesh Patel
 
Y

Yogs

I could, but what do I do if it wasn't added. I was under the understanding
that the fill command adds the table even if there are 0 records. Is that
not true?

Thanks!
 

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