Object reference not set...

A

Amy Snyder

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("DataSourceConnectionString"))
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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top