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. Error

Error

Scheduled Pinned Locked Moved C#
databasesecurityhelp
5 Posts 5 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
    minniemooo
    wrote on last edited by
    #1

    Error :Object reference not set to an instance of an object. Here is my code. SqlConnection conn = new SqlConnection("Data Source=servername;Database=dbCustom;Integrated Security=SSPI"); SqlCommand comm = new SqlCommand("GetProjects", conn); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet ds = new DataSet(); adapter.Fill(ds, "Project_ID"); ProjectidList.DataSource = ds; * it says error is on this line ProjectidList.DataMember = ds.ToString();

    A A V K 4 Replies Last reply
    0
    • M minniemooo

      Error :Object reference not set to an instance of an object. Here is my code. SqlConnection conn = new SqlConnection("Data Source=servername;Database=dbCustom;Integrated Security=SSPI"); SqlCommand comm = new SqlCommand("GetProjects", conn); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet ds = new DataSet(); adapter.Fill(ds, "Project_ID"); ProjectidList.DataSource = ds; * it says error is on this line ProjectidList.DataMember = ds.ToString();

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      Are there any values in the dataset. Your query might fail and in the dataset there are no tables...thus generating an error.

      I will use Google before asking dumb questions

      1 Reply Last reply
      0
      • M minniemooo

        Error :Object reference not set to an instance of an object. Here is my code. SqlConnection conn = new SqlConnection("Data Source=servername;Database=dbCustom;Integrated Security=SSPI"); SqlCommand comm = new SqlCommand("GetProjects", conn); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet ds = new DataSet(); adapter.Fill(ds, "Project_ID"); ProjectidList.DataSource = ds; * it says error is on this line ProjectidList.DataMember = ds.ToString();

        A Offline
        A Offline
        Anthony Mushrow
        wrote on last edited by
        #3

        Im gonna guess that something went wrong when you tried to fill your dataset, or ProjectidList was not initialised properly. Add an if statement to see if either of them are null or something.

        My current favourite word is: PIE! Good ol' pie, it's been a while.

        1 Reply Last reply
        0
        • M minniemooo

          Error :Object reference not set to an instance of an object. Here is my code. SqlConnection conn = new SqlConnection("Data Source=servername;Database=dbCustom;Integrated Security=SSPI"); SqlCommand comm = new SqlCommand("GetProjects", conn); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet ds = new DataSet(); adapter.Fill(ds, "Project_ID"); ProjectidList.DataSource = ds; * it says error is on this line ProjectidList.DataMember = ds.ToString();

          V Offline
          V Offline
          Vasudevan Deepak Kumar
          wrote on last edited by
          #4

          Two reasons: 1) Are you missing a runat="server" for ProjectidList in the ASPX page? 2) Is ds null?

          Vasudevan Deepak Kumar Personal Homepage
          Tech Gossips
          A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

          1 Reply Last reply
          0
          • M minniemooo

            Error :Object reference not set to an instance of an object. Here is my code. SqlConnection conn = new SqlConnection("Data Source=servername;Database=dbCustom;Integrated Security=SSPI"); SqlCommand comm = new SqlCommand("GetProjects", conn); SqlDataAdapter adapter = new SqlDataAdapter(comm); DataSet ds = new DataSet(); adapter.Fill(ds, "Project_ID"); ProjectidList.DataSource = ds; * it says error is on this line ProjectidList.DataMember = ds.ToString();

            K Offline
            K Offline
            kkadir
            wrote on last edited by
            #5

            Before, adapter.Fill(ds, "Project_ID"); , open your connection , conn.Open(); While you forgot this the dataset is null so as it says object reference not set to an instance of an object. Regards.

            .:: Something is Wrong ::.

            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