473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Object reference not set...

I have the following sub that is called to load a data grid. It works
without a problem until I uncomment the dv.sort line. When I uncomment
the line I get the error: Object reference not set to an instance of an
object. The error is pointing to that line. What am I doing wrong?

Public Sub LoadGrid()
Dim ds As New Data.DataSet
Dim dv As New Data.DataView
Dim strSQL As String

strSQL ="my sql statement"

ds = DataHandler.GetDataSet(strSQL,
ConfigurationSettings.AppSettings("DataSourceConne ctionString"))
dv = CType(ds, DataSet).Tables(0).DefaultView

HandleSort(SortExpression)
'dv.Sort = Session("Sort").ToString & " " &
Session("SortDirection").ToString

dg.DataSource = dv
dg.DataBind()
lblLegend.Visible = True

End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
2 882
Are those two session variable not null?

"Amy Snyder" <am**@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I have the following sub that is called to load a data grid. It works
without a problem until I uncomment the dv.sort line. When I uncomment
the line I get the error: Object reference not set to an instance of an
object. The error is pointing to that line. What am I doing wrong?

Public Sub LoadGrid()
Dim ds As New Data.DataSet
Dim dv As New Data.DataView
Dim strSQL As String

strSQL ="my sql statement"

ds = DataHandler.GetDataSet(strSQL,
ConfigurationSettings.AppSettings("DataSourceConne ctionString"))
dv = CType(ds, DataSet).Tables(0).DefaultView

HandleSort(SortExpression)
'dv.Sort = Session("Sort").ToString & " " &
Session("SortDirection").ToString

dg.DataSource = dv
dg.DataBind()
lblLegend.Visible = True

End Sub


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Amy -

You need to do a nothing (null) check on those before you can use them to make sure they are not null.

For instance:

If Not IsNothing(Session("Sort")) then
' this one is okay
else
' take some measures
end if

If Not IsNothing(Session("SortDirection"))
' this one is also okay
else
' take some measures
end if

Now they should be good to go.
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris S. | last post by:
I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
29
by: web1110 | last post by:
If I have 2 variables, A and B, referencing the same object and then do a A.Dispose(), what happens to B?
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
16
by: anonymous.user0 | last post by:
The way I understand it, if I have an object Listener that has registered as a listener for some event Event that's produced by an object Emitter, as long as Emitter is still allocated Listener...
7
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.