Data Table Error
-
//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. -
//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.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
-
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
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.
-
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.
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
-
//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.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; } -
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; }//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. -
//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.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
-
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
My debugger doesn't work, it has a problem doing remote debugging, how do I set that up?