HELP: System.NullReferenceException Error

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

(Using Whidbey, but I don't think it matters.)

I keep getting this error:
System.NullReferenceException: Object reference not set to an instance
of an object.

Here is the line it's happening to:
dv.RowFilter = "CustomerID='" & value & "'"
(It is happening in the property "Set" code below.)

The dv variable IS declared at a larger scope. What is happening? See code
below....

Public Class Sheet1
Private dv As DataView

Private Sub Sheet1_Initialize(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Initialize
Try
Dim uc1 As New UserControl1

Me.CustomersTableAdapter1.Fill(Me.DsCustomersOrders1.Customers)
Me.OrdersTableAdapter1.Fill(Me.DsCustomersOrders1.Orders)

Dim dv As New DataView(Me.DsCustomersOrders1.Orders)
dv.AllowEdit = False

'Dim uc1 As New ExcelApplication1.UserControl1
Globals.ThisWorkbook.ActionsPane.Controls.Add(uc1)

List1.SetDataBinding(dv, "", "CustomerID", "OrderDate",
"ShippedDate")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Public Property CustomerId() As String
Get
End Get
Set(ByVal value As String)
Try
' ERROR IS HAPPENING HERE
dv.RowFilter = "CustomerID='" & value & "'"
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Set
End Property
End Class
 
Is customer id being set before the Initailize event fires from the Sheet?

is Value null?
 
I figured it out.

In Sheet1_Initialize I did this:
Dim dv As New DataView(Me.DsCustomersOrders1.Orders)
Instead of this:
dv = New DataView(Me.DsCustomersOrders1.Orders)

LOL - I'm a dork.

Thanks!
 
I am sure you do,

:-))

Private dv As DataView
Sub
Dim dv As New DataView(Me.DsCustomersOrders1.Orders)
End Sub
Public Property CustomerId() As String
dv.RowFilter = "CustomerID='" & value & "'"
End Class
 
I am sure you do,
:-))

Private dv As DataView
Sub
Dim dv As New DataView(Me.DsCustomersOrders1.Orders)

^^^^ isn't this creating a localized instance of the DataView? So when the
scope leaves this sub, this Dataview will be inaccessable.
End Sub
Public Property CustomerId() As String
dv.RowFilter = "CustomerID='" & value & "'"


^^^^ this is still looking at the class level dataview??? not the local
declared within that method.
 
Back
Top