Windows App datarow error


Jun 3, 2004
Programming Experience
am writing an application where my user makes a selection with a combo box and then it pulls up the appropriate information for the selection. If the user approves of the selection he clicks a button which adds the information to another dataset.

Everything works fine except when the button is clicked to add the information to the dataset.

I get the error Object reference not set to an instance of an object.

Here should be the appropriate code:

This is the button to add the information to the dataset. The DataTier is a separate class for all of my data manipulation.

Private Sub btnAddPO_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnAddPO.Click
Dim ds As DataSet
Dim strDate As Date = Today
Dim strPO As String = mstrSelectedPO
Dim strSpend As String = Me.lblSpend.Text
Dim strVend As String = Me.lblVendor.Text
Dim strBuy As String = Me.lblBuyer.Text

mobjDataTier = New DataTier
ds = mobjDataTier.AddAGPO(strDate, strPO, strSpend, strVend, strBuy)

Me.dgAGPOs.DataSource = ds
Me.dgAGPOs.DataMember = "AGPOInfo"
End Sub

This is the code in my data class which is giving me the error:

Public Function AddAGPO(ByVal strDate As String, _
ByVal strPONum As String, _
ByVal strSpend As String, _
ByVal strVend As String, _
ByVal strBuyer As String) _
As DataSet
If blnCreated = False Then
dsAGPOs = New DataSet
With dsAGPOs.Tables.Add("AGPO")
.Columns.Add("ToAG", GetType(String))
.Columns.Add("PONum", GetType(String))
.Columns.Add("Vendor", GetType(String))
.Columns.Add("Buyer", GetType(String))
End With

blnCreated = True
End If

Dim myRow As DataRow

myRow = dsAGPOs.Tables("AGPOInfo").NewRow ‘This is the row that is causing the error.

myRow.Item(0) = strDate
myRow.Item(1) = strPONum
myRow.Item(2) = strSpend
myRow.Item(3) = strVend
myRow.Item(4) = strBuyer


Return dsAGPOs

Catch ex As Exception

End Try

End Function

Any Ideas?
Top Bottom