CODEDIGEST InstallShield
Home Articles CodeDigest Tutorials InstallShield FAQs
Skip Navigation LinksHome » CodeDigest » Copy the Sorted/Filtered Dataview To DataTable in .Net 1.1   You are not logged in.
Search
 

Sponsors
InstallShield
 

Sponsored Links
 

Technologies
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Copy the Sorted/Filtered Dataview To DataTable in .Net 1.1
Copy the Sorted/Filtered Dataview To DataTable in .Net 1.1
Submitted By Satheesh Babu
On 12/8/2008 8:47:12 AM
Tags: C#,CodeDigest  

Copy the Sorted Dataview To DataTable in .Net 1.1

 

The below code can be used to copy the sorted DataView object to a DataTable object.  

 

dt=dv.Table.Clone();

// Clones the structure of table 

int i = 0;

string [] ColNames = new string[dt.Columns.Count];

foreach (DataColumn col in dt.Columns)

{

ColNames[i++] = col.ColumnName;  

//Getting the column names to a string Array  

} 

IEnumerator Ienum = dv.GetEnumerator();  

// Get the enumerator that can iterate through a collection 

while (enum.MoveNext())

{

DataRowView drv = (DataRowView)Ienum.Current; 

// Gets the Current element in the collection,ie.DataRowView  

DataRow dr = dt.NewRow();

try

{

foreach (string strName in ColNames)

 

dr[strName] = drv[strName];

// Copy the data to Datatable 

}

 }

catch (Exception ex)

{

Response.Write(ex.Message);

}

dt.Rows.Add(dr);

}

 

 In the above code, dv contains the sorted DataView object.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!