troubleshooting Question

What is the correct syntax for adding a datarow to a dataset

Avatar of Olukayode Oluwole
Olukayode OluwoleFlag for Canada asked on
C#
2 Comments1 Solution70 ViewsLast Modified:
While trying load Grid Data using a dataset I have a  syntax error
when specifying the content of a given row.

The Script for creating a new row  in the Grid (named  dgvDetailsTable) is shown below

DataTable dt = dgvDetailsTable.DataSource as DataTable;
            dt = new DataTable();
            DataSet ds = new DataSet();
            ds.Tables.Add("education");
            DataRow dr = ds.Tables[0].NewRow();

            //  Define Data  Columns
            dt.Columns.Add(new DataColumn("staff_no"));
            dt.Columns.Add(new DataColumn("schoolname"));
            dt.Columns.Add(new DataColumn("startdate"));
            dt.Columns.Add(new DataColumn("enddate"));
            dt.Columns.Add(new DataColumn("yearsexp"));
            dt.Columns.Add(new DataColumn("degreecode"));
            dt.Columns.Add(new DataColumn("Companycode"));
            dt.Columns.Add(new DataColumn("EmpId"));
            dt.Columns.Add(new DataColumn("EmpEduId"));

	    //  Specify a typical rows Data
            dr["staff_no"] = StaffNoValue.Text;
            dr["schoolname"] = string.Empty;
            dr["startdate"] = dateTimePicker1.Value.ToString("dd-mm-yyyy");
            dr["enddate"] = dateTimePicker2.Value.ToString("dd-mm-yyyy");
            dr["yearsexp"] = string.Empty;
            dr["degreecode"] = string.Empty;
            dr["Companycode"] = CompanyCodeValue.Text;
            dr["EmpId"] = Convert.ToInt32(IdValue.Text);
            dr["EmpEduId"] = 0;

            ds.Tables[0].Rows.Add(dr);

And the error in debugger mode is shown below

Error while constituting a Row in my DataSet
Kindly assist to know how to specify the row

Thanks

Olukay
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros