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. C#
  4. Object reference not set to instance of an object

Object reference not set to instance of an object

Scheduled Pinned Locked Moved C#
saleshelp
4 Posts 2 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.
  • M Offline
    M Offline
    Mamphekgo
    wrote on last edited by
    #1

    i am trying to run this code but it always gives me this error"Object reference not set to instance of an object" and here is my code try { DataAcces datc=new DataAcces(); this.txtID.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerID"); this.txtName.DataBindings.Add("Text",datc.dsDisplay.Tables["Customer"],"CustomerName"); this.txtSurname.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerSurname"); this.txtEmail.DataBindings.Add("Text",datc.dsDisplay.Tables["CustomerEmail"],"CustomerEmail"); } catch(Exception ex) { MessageBox.Show(ex.Message); }

    C 1 Reply Last reply
    0
    • M Mamphekgo

      i am trying to run this code but it always gives me this error"Object reference not set to instance of an object" and here is my code try { DataAcces datc=new DataAcces(); this.txtID.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerID"); this.txtName.DataBindings.Add("Text",datc.dsDisplay.Tables["Customer"],"CustomerName"); this.txtSurname.DataBindings.Add("Text",datc.dsDisplay.Tables["Customers"],"CustomerSurname"); this.txtEmail.DataBindings.Add("Text",datc.dsDisplay.Tables["CustomerEmail"],"CustomerEmail"); } catch(Exception ex) { MessageBox.Show(ex.Message); }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Have you stepped through in a debugger to see which line is giving you a null reference ? What's DataAcces ? The typo tells me it's not a framework class, so we can't possibly know what it does, how it works, or why you may have this error. The controls could be null. The dsDisplay property could be null. It may not contain a table called 'Customers'. Etc.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      M 1 Reply Last reply
      0
      • C Christian Graus

        Have you stepped through in a debugger to see which line is giving you a null reference ? What's DataAcces ? The typo tells me it's not a framework class, so we can't possibly know what it does, how it works, or why you may have this error. The controls could be null. The dsDisplay property could be null. It may not contain a table called 'Customers'. Etc.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        M Offline
        M Offline
        Mamphekgo
        wrote on last edited by
        #3

        yes i did.it gives me this error on the first line

        C 1 Reply Last reply
        0
        • M Mamphekgo

          yes i did.it gives me this error on the first line

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          IF you mean DataAcces datc=new DataAcces(); then you need to step into the code, something in the constructor for your class is failing. If this is a data tier, the methods should probably be static, so you don't need to create one every time.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          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