TableAdapter cant fill DataSet

cjard

Well-known member
Joined
Apr 25, 2006
Messages
7,081
Programming Experience
10+
I have a DataSet, call it TmpDS
and i have a table in it called TmpTable which has a matching adapter.

I say:
VB.NET:
Dim x as New TmpTableAdatper
x.Fill(TmpDS.TmpTable)
but it crashes with a null pointer exception. Both references are inited to a value, so it's something else. I think I might have forgotten to set the connection object, but then.. i've always had VS create datasets and add them to my forms etc, so im not sure what other init code i've missed. Can anyone provide any pointers?

tia
 
Last edited by a moderator:
You may want to try something as below:

VB.NET:
Dim strSQL AsString = "SELECT * FROM JOB "
Dim cnn AsNew SqlClient.SqlConnection
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim aString As String
 
cnn.ConnectionString = YOUR Connection
 
Dim myCommand AsNew SqlDataAdapter(strSQL, cnn)
Dim ds AsNew DataSet
myCommand.Fill(ds, "JOBS")
DataGrid1.DataSource = ds
DataGrid1.DataBind()
cnn.Close()


http://www.programmingknowledge.com/


 
Last edited by a moderator:
cjard - in mt sig there's a couple of ADO.NET tutorials that will help walk you through all the steps. Check them out and see if they are of any use.

-tg
 
i found out the cause, FYI..

The dataset has an event "Initiliazed" and i'd have through that this, from the name of it, fired after the object was ready for use, but it appears it wasnt..

so the code i put in to fill my dataset lookup tables (values that dont change) went in this event but it crashed. i now have to put it in whichever sub is making the new dataset, and it works fine:


VB.NET:
Module1
 
  Protected lookupDS as New LookupDS
 
  Sub Main()
    DIm x as new LookupDSTableAdapters.SomeTableAdapter
    x.Fill(lookupDS.SomeTable)
  End Sub
End Module
 
Back
Top