Tuesday 27 August 2013

Adding multiple rows to DataTable

Adding multiple rows to DataTable

I know two ways to add new row with data to a DataTable
string[] arr2 = { "one", "two", "three" };
dtDeptDtl.Columns.Add("Dept_Cd");



for (int a = 0; a < arr2.Length; a++)
{
DataRow dr2 = dtDeptDtl.NewRow();
dr2["Dept_Cd"] = DeptCd[a];
dtDeptDtl.Rows.Add(dr2);
}



for (int a = 0; a < arr2.Length; a++)
{
dtDeptDtl.Rows.Add();
dtDeptDtl.Rows[a]["Dept_Cd"] = DeptCd[a];
}
Both the above methods will give me the same result i.e One Two Three will
be added in DataTable in seperate rows.
But my question is that what is the difference between both the steps and
which one is better way performance wise?

No comments:

Post a Comment