Thursday, March 29, 2012

Object reference

The error is:
Object reference not set to an instance of an object. (See commented line below---)
I tried using the new keyword and that does not solve the problem.
Do you see the problem?

Private Sub LoadData(ByVal SortKey As String)

Dim strPath As String = Server.MapPath(Request.ApplicationPath)
Dim ds As New DataSet()
ds.ReadXmlSchema(strPath & "\XML\A.xsd")
ds.ReadXml(strPath & "\XML\A.xml")

'------This line gives the error------------
Dim view As DataView = ds.Tables("Orders").DefaultView
'------------------
If Not (SortKey Is Nothing) And SortKey <> [String].Empty Then
view.Sort = SortKey
End If
dgUsers.DataSource = view
dgUsers.DataBind()
End SubOne problem i see is that you never name a table "Orders" but try to reference it anyway. If you only have one table try referencing ds.Tables(0).DefaultView. Or, ds.Table(0).TableName = "Orders" then use ds.Tables("Orders").DefaultView.

0 comments:

Post a Comment