Avatar of Olukayode Oluwole
Olukayode Oluwole
Flag for Canada asked on

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

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);

Open in new window


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
C#

Avatar of undefined
Last Comment
Olukayode Oluwole

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Chinmay Patel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Olukayode Oluwole

ASKER
Thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck