Connecting Tech Pros Worldwide Forums | Help | Site Map

HELP: System.NullReferenceException Error

VB Programmer
Guest
 
Posts: n/a
#1: Nov 20 '05
(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.DsCustomersOrder s1.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



CJ Taylor
Guest
 
Posts: n/a
#2: Nov 20 '05

re: HELP: System.NullReferenceException Error


Is customer id being set before the Initailize event fires from the Sheet?

is Value null?


"VB Programmer" <RobertNZana*NoSpam-Please*@juno.com> wrote in message
news:OTTRVv0QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=blue]
> (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[/color]
code[color=blue]
> below....
>
> Public Class Sheet1
> Private dv As DataView
>
> Private Sub Sheet1_Initialize(ByVal sender As System.Object, ByVal e[/color]
As[color=blue]
> System.EventArgs) Handles Me.Initialize
> Try
> Dim uc1 As New UserControl1
>
>[/color]
Me.CustomersTableAdapter1.Fill(Me.DsCustomersOrder s1.Customers)[color=blue]
> 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
>
>[/color]


VB Programmer
Guest
 
Posts: n/a
#3: Nov 20 '05

re: HELP: System.NullReferenceException Error


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!

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:u4FSEy0QEHA.1620@TK2MSFTNGP12.phx.gbl...[color=blue]
> Is customer id being set before the Initailize event fires from the Sheet?
>
> is Value null?
>
>
> "VB Programmer" <RobertNZana*NoSpam-Please*@juno.com> wrote in message
> news:OTTRVv0QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=green]
> > (Using Whidbey, but I don't think it matters.)
> >
> > I keep getting this error:
> > System.NullReferenceException: Object reference not set to an[/color][/color]
instance[color=blue][color=green]
> > 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[/color]
> code[color=green]
> > below....
> >
> > Public Class Sheet1
> > Private dv As DataView
> >
> > Private Sub Sheet1_Initialize(ByVal sender As System.Object, ByVal e[/color]
> As[color=green]
> > System.EventArgs) Handles Me.Initialize
> > Try
> > Dim uc1 As New UserControl1
> >
> >[/color]
> Me.CustomersTableAdapter1.Fill(Me.DsCustomersOrder s1.Customers)[color=green]
> > 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
> >
> >[/color]
>
>[/color]


CJ Taylor
Guest
 
Posts: n/a
#4: Nov 20 '05

re: HELP: System.NullReferenceException Error


I don't see how that solves your rowfilter problem...


"VB Programmer" <RobertNZana*NoSpam-Please*@juno.com> wrote in message
news:e29aV40QEHA.3608@TK2MSFTNGP10.phx.gbl...[color=blue]
> 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!
>
> "CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
> news:u4FSEy0QEHA.1620@TK2MSFTNGP12.phx.gbl...[color=green]
> > Is customer id being set before the Initailize event fires from the[/color][/color]
Sheet?[color=blue][color=green]
> >
> > is Value null?
> >
> >
> > "VB Programmer" <RobertNZana*NoSpam-Please*@juno.com> wrote in message
> > news:OTTRVv0QEHA.1960@TK2MSFTNGP10.phx.gbl...[color=darkred]
> > > (Using Whidbey, but I don't think it matters.)
> > >
> > > I keep getting this error:
> > > System.NullReferenceException: Object reference not set to an[/color][/color]
> instance[color=green][color=darkred]
> > > 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?[/color][/color][/color]
See[color=blue][color=green]
> > code[color=darkred]
> > > below....
> > >
> > > Public Class Sheet1
> > > Private dv As DataView
> > >
> > > Private Sub Sheet1_Initialize(ByVal sender As System.Object, ByVal[/color][/color][/color]
e[color=blue][color=green]
> > As[color=darkred]
> > > System.EventArgs) Handles Me.Initialize
> > > Try
> > > Dim uc1 As New UserControl1
> > >
> > >[/color]
> > Me.CustomersTableAdapter1.Fill(Me.DsCustomersOrder s1.Customers)[color=darkred]
> > > 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
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]


Cor Ligthert
Guest
 
Posts: n/a
#5: Nov 20 '05

re: HELP: System.NullReferenceException Error


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


CJ Taylor
Guest
 
Posts: n/a
#6: Nov 20 '05

re: HELP: System.NullReferenceException Error


> I am sure you do,[color=blue]
>
> :-))
>
> Private dv As DataView
> Sub
> Dim dv As New DataView(Me.DsCustomersOrders1.Orders)[/color]

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


^^^^ this is still looking at the class level dataview??? not the local
declared within that method.
[color=blue]
> End Class
>[/color]

[color=blue]
>[/color]


Cor Ligthert
Guest
 
Posts: n/a
#7: Nov 20 '05

re: HELP: System.NullReferenceException Error


Hi CJ,

You get a 10 from me, what means here Excellent

:-))

Cor


CJ Taylor
Guest
 
Posts: n/a
#8: Nov 20 '05

re: HELP: System.NullReferenceException Error


Cheers mate =)

"Cor Ligthert" <notfirstname@planet.nl> wrote in message
news:ugdKTq1QEHA.2404@TK2MSFTNGP09.phx.gbl...[color=blue]
> Hi CJ,
>
> You get a 10 from me, what means here Excellent
>
> :-))
>
> Cor
>
>[/color]


Closed Thread