CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150

    Unhappy Passing back a DataSet....

    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

  2. #2
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169
    Try Dim myDataSet As New DataSet in Button3_Click or something other than "myDataSet".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured