Home > .Net Framework > DataRow to DataTable

DataRow to DataTable

A simple method for convert DataRow to DataTable on C#

 public static DataTable ArrDataRowToDataTable(DataRow[] arrDataRow, DataTable originalDataTable)
            int colCount = originalDataTable.Columns.Count;
            int rowResult = arrDataRow.Length;
            DataTable tempDt = new DataTable();
            DataColumn[] arrDc = new DataColumn[colCount];
            originalDataTable.Columns.CopyTo(arrDc, 0);
            foreach (DataColumn dc in arrDc)
                tempDt.Columns.Add(dc.ColumnName, dc.DataType);
            foreach (DataRow dr in arrDataRow)
                object[] temp = new object[colCount];
                for (int iCounter = 0; iCounter < arrDc.Length; iCounter++)
                    temp[iCounter] = dr[iCounter];
            return tempDt;
Categories: .Net Framework Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: