Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Object reference error

Object reference error

Scheduled Pinned Locked Moved Visual Basic
cssdesignxmlhelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nickiii
    wrote on last edited by
    #1

    Hi All: I'm trying to dynamically create a datagrid and fill it with XML data. But I get an "Object reference not set to an instance of an object." error when running it. See the code below. What am I missing? Public Sub CreateDynamicGrid() Dim ds As New DataSet Dim grid As System.Web.UI.WebControls.DataGrid Try 'Place the XML information into a dataset ds.ReadXml("C:\Temp\test.xml") 'The dataset is used as the data source for our newly created datatrid grid grid.DataSource = ds grid.DataBind() 'grid is added to the PlaceHolder PlaceHolder.Controls.Add(grid) Catch ex As Exception Response.Write(ex.Message.ToString) End Try End Sub Thanks in advance!

    T G 2 Replies Last reply
    0
    • N nickiii

      Hi All: I'm trying to dynamically create a datagrid and fill it with XML data. But I get an "Object reference not set to an instance of an object." error when running it. See the code below. What am I missing? Public Sub CreateDynamicGrid() Dim ds As New DataSet Dim grid As System.Web.UI.WebControls.DataGrid Try 'Place the XML information into a dataset ds.ReadXml("C:\Temp\test.xml") 'The dataset is used as the data source for our newly created datatrid grid grid.DataSource = ds grid.DataBind() 'grid is added to the PlaceHolder PlaceHolder.Controls.Add(grid) Catch ex As Exception Response.Write(ex.Message.ToString) End Try End Sub Thanks in advance!

      T Offline
      T Offline
      Tom John
      wrote on last edited by
      #2

      Hi Nicki Which line is thowing the error? Maybe loose the Try/Catch whilst debugging the problem. Cheers Tom

      N 1 Reply Last reply
      0
      • T Tom John

        Hi Nicki Which line is thowing the error? Maybe loose the Try/Catch whilst debugging the problem. Cheers Tom

        N Offline
        N Offline
        nickiii
        wrote on last edited by
        #3

        Hi Tom: It's this line: --------------------- grid.DataSource = ds --------------------- I don't understand how the dataset could be blank. The file I'm pointing to in the ReadXML method has data in it.

        T 1 Reply Last reply
        0
        • N nickiii

          Hi All: I'm trying to dynamically create a datagrid and fill it with XML data. But I get an "Object reference not set to an instance of an object." error when running it. See the code below. What am I missing? Public Sub CreateDynamicGrid() Dim ds As New DataSet Dim grid As System.Web.UI.WebControls.DataGrid Try 'Place the XML information into a dataset ds.ReadXml("C:\Temp\test.xml") 'The dataset is used as the data source for our newly created datatrid grid grid.DataSource = ds grid.DataBind() 'grid is added to the PlaceHolder PlaceHolder.Controls.Add(grid) Catch ex As Exception Response.Write(ex.Message.ToString) End Try End Sub Thanks in advance!

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          You haven't created any DataGrid object, only a reference that can be used for the object.

          --- single minded; short sighted; long gone;

          N 1 Reply Last reply
          0
          • N nickiii

            Hi Tom: It's this line: --------------------- grid.DataSource = ds --------------------- I don't understand how the dataset could be blank. The file I'm pointing to in the ReadXML method has data in it.

            T Offline
            T Offline
            Tom John
            wrote on last edited by
            #5

            I don't think it's the dataset, It looks like you have not instantiated the grid. ... as Guffa has already eluded to ;) Hope this helps Tom -- modified at 12:51 Monday 11th June, 2007

            1 Reply Last reply
            0
            • G Guffa

              You haven't created any DataGrid object, only a reference that can be used for the object.

              --- single minded; short sighted; long gone;

              N Offline
              N Offline
              nickiii
              wrote on last edited by
              #6

              You're right Guffa. It works now, thanks!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups