Click to See Complete Forum and Search --> : Passing back a DataSet....


nolc
June 20th, 2002, 08:08 AM
Do you see something wrong here? When I pass back the Dataset to Button3_Click…I error out.

ERROR: Object reference not set to an instance of an object.


[code]
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim OrdNum As String = Text1.Text
Dim myDataSet As DataSet
Dim Party As PartyDB = New PartyDB()

myDataSet = Party.GetAllParties(OrdNum)

Dim myDataTable As DataTable
myDataTable = myDataSet.Tables("GetAllParties")

MessageBox.Show(myDataTable.Rows.Count.ToString)

End Sub

-----------------------------------------------

Public Function GetAllParties(ByVal OrderNumber As String) As DataSet
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New SqlConnection(strConn)

Dim myCommand As SqlDataAdapter = New SqlDataAdapter("sp_GetAllParties", myConnection)

' Mark the Command as a SPROC
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterOrderNumber As SqlParameter = New SqlParameter("@OrderNumber", SqlDbType.NVarChar, 50)
parameterOrderNumber.Value = OrderNumber
myCommand.SelectCommand.Parameters.Add(parameterOrderNumber)

' Create and Fill the DataSet
Dim myDataSet As New DataSet()
myCommand.Fill(myDataSet, "GetAllParties")

' Return the dataset to the calling function
Return myDataSet

myConnection.Close()

End Function

enigmaos
June 20th, 2002, 10:26 AM
Try Dim myDataSet As New DataSet in Button3_Click or something other than "myDataSet".