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

Data Table Error

Scheduled Pinned Locked Moved C#
helpdatabase
8 Posts 4 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.
  • E Offline
    E Offline
    Expert Coming
    wrote on last edited by
    #1

    //Create the variables and arrays need only for Creating the table string[] skills = new string[1]; skills[0] = "attack"; //skills[1] = "strength"; //skills[2] = "defence"; //The creation of the table that shows the user their stats from the database //Dynamic Creation of the datatable ///Also sets up the new datatable DataTable dtshowskills = new DataTable("USkills"); DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add("userSkill"); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add("userLevel"); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["userSkill"] = skill; drskill["userLevel"] = 0; dtshowskills.Rows.Add(drskill); } dgSkills.DataSource = dtshowskills; dgSkills.DataBind(); //This is on my actual web page I don't understand DataTables, and I am going to do some reading up on them, but for now, someone please help me. I had help on most of it a while ago, any help is appricated.

    A G 2 Replies Last reply
    0
    • E Expert Coming

      //Create the variables and arrays need only for Creating the table string[] skills = new string[1]; skills[0] = "attack"; //skills[1] = "strength"; //skills[2] = "defence"; //The creation of the table that shows the user their stats from the database //Dynamic Creation of the datatable ///Also sets up the new datatable DataTable dtshowskills = new DataTable("USkills"); DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add("userSkill"); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add("userLevel"); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["userSkill"] = skill; drskill["userLevel"] = 0; dtshowskills.Rows.Add(drskill); } dgSkills.DataSource = dtshowskills; dgSkills.DataBind(); //This is on my actual web page I don't understand DataTables, and I am going to do some reading up on them, but for now, someone please help me. I had help on most of it a while ago, any help is appricated.

      A Offline
      A Offline
      Andy Brummer
      wrote on last edited by
      #2

      I'm not sure what error you are getting since you didn't list it, but I'm guessing it is because you havne't set the data types of the DataColumns. Post the problem and we can help you out.


      I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

      E 1 Reply Last reply
      0
      • A Andy Brummer

        I'm not sure what error you are getting since you didn't list it, but I'm guessing it is because you havne't set the data types of the DataColumns. Post the problem and we can help you out.


        I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

        E Offline
        E Offline
        Expert Coming
        wrote on last edited by
        #3

        Oops, sorry I thought that I did post the error. My bad. Here is the error: System.NullReferenceException: Object reference not set to an instance of an object.

        A 1 Reply Last reply
        0
        • E Expert Coming

          Oops, sorry I thought that I did post the error. My bad. Here is the error: System.NullReferenceException: Object reference not set to an instance of an object.

          A Offline
          A Offline
          Alomgir Miah
          wrote on last edited by
          #4

          DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add("userSkill"); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add("userLevel"); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["userSkill"] = skill; drskill["userLevel"] = 0; dtshowskills.Rows.Add(drskill); } should instead read DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add(userSkill); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add(userLevel); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["Skill"] = skill; drskill["Level"] = 0; dtshowskills.Rows.Add(drskill); } Live Life King Size Alomgir Miah

          1 Reply Last reply
          0
          • E Expert Coming

            //Create the variables and arrays need only for Creating the table string[] skills = new string[1]; skills[0] = "attack"; //skills[1] = "strength"; //skills[2] = "defence"; //The creation of the table that shows the user their stats from the database //Dynamic Creation of the datatable ///Also sets up the new datatable DataTable dtshowskills = new DataTable("USkills"); DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add("userSkill"); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add("userLevel"); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["userSkill"] = skill; drskill["userLevel"] = 0; dtshowskills.Rows.Add(drskill); } dgSkills.DataSource = dtshowskills; dgSkills.DataBind(); //This is on my actual web page I don't understand DataTables, and I am going to do some reading up on them, but for now, someone please help me. I had help on most of it a while ago, any help is appricated.

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

            You are creating DataColumn objects, but you don't use them. Instead you create columns that have the same name as the variables. To use the DataColumn objects that you create, do like this: DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add(userSkill); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add(userLevel); The columns will now be named "Skill" and "Level". --- b { font-weight: normal; }

            E 1 Reply Last reply
            0
            • G Guffa

              You are creating DataColumn objects, but you don't use them. Instead you create columns that have the same name as the variables. To use the DataColumn objects that you create, do like this: DataColumn userSkill = new DataColumn("Skill"); dtshowskills.Columns.Add(userSkill); DataColumn userLevel = new DataColumn("Level"); dtshowskills.Columns.Add(userLevel); The columns will now be named "Skill" and "Level". --- b { font-weight: normal; }

              E Offline
              E Offline
              Expert Coming
              wrote on last edited by
              #6

              //Create the variables and arrays need only for Creating the table string[] skills = new string[1]; skills[0] = "attack"; //skills[1] = "strength"; //skills[2] = "defence"; //The creation of the table that shows the user their stats from the database //Dynamic Creation of the datatable ///Also sets up the new datatable DataTable dtshowskills = new DataTable("USkills"); DataColumn dcuserSkill = new DataColumn("Skill"); dcuserSkill.DataType = System.Type.GetType("System.String"); dtshowskills.Columns.Add(dcuserSkill); DataColumn dcuserLevel = new DataColumn("Level"); dcuserLevel.DataType = System.Type.GetType("System.Int32"); dtshowskills.Columns.Add(dcuserLevel); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["Skill"] = skill; drskill["Level"] = 0; dtshowskills.Rows.Add(drskill); } dgSkills.DataSource = dtshowskills; dgSkills.DataBind(); Error is now: System.NullReferenceException: Object reference not set to an instance of an object.

              A 1 Reply Last reply
              0
              • E Expert Coming

                //Create the variables and arrays need only for Creating the table string[] skills = new string[1]; skills[0] = "attack"; //skills[1] = "strength"; //skills[2] = "defence"; //The creation of the table that shows the user their stats from the database //Dynamic Creation of the datatable ///Also sets up the new datatable DataTable dtshowskills = new DataTable("USkills"); DataColumn dcuserSkill = new DataColumn("Skill"); dcuserSkill.DataType = System.Type.GetType("System.String"); dtshowskills.Columns.Add(dcuserSkill); DataColumn dcuserLevel = new DataColumn("Level"); dcuserLevel.DataType = System.Type.GetType("System.Int32"); dtshowskills.Columns.Add(dcuserLevel); foreach (string skill in skills) { DataRow drskill = dtshowskills.NewRow(); drskill["Skill"] = skill; drskill["Level"] = 0; dtshowskills.Rows.Add(drskill); } dgSkills.DataSource = dtshowskills; dgSkills.DataBind(); Error is now: System.NullReferenceException: Object reference not set to an instance of an object.

                A Offline
                A Offline
                Alomgir Miah
                wrote on last edited by
                #7

                I checked your code. It works just fine. Can you debug your code and tell us exactly in which line you get the error. Live Life King Size Alomgir Miah

                E 1 Reply Last reply
                0
                • A Alomgir Miah

                  I checked your code. It works just fine. Can you debug your code and tell us exactly in which line you get the error. Live Life King Size Alomgir Miah

                  E Offline
                  E Offline
                  Expert Coming
                  wrote on last edited by
                  #8

                  My debugger doesn't work, it has a problem doing remote debugging, how do I set that up?

                  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