Split DataTable into multiple tables

Consider a DataTable with a column name salary, following code splits the DataTable on the basis of values in salary column, i.e all the rows in DataTable with same salary will come into one DataTable.

DataTable dt= new DataTable();
dt = objEmployee.getDetails(); // Get Data from Database
if (dt.Rows.Count > 0)
{
List<DataTable> result = dt.AsEnumerable().GroupBy(row => row.Field<int>(“salary”)).Select(g => g.CopyToDataTable()).ToList();
int noOfTables = result.Count;

DataTable dtCommonSalary= new DataTable();
for (int loop= 0; loop < noOfTables; loop++)
{
dtCommonSalary= result[loop] as DataTable;
DisplayResultBySalary(dtCommonSalary);
}
}
// DisplayResultBysalary definition
DisplayResultBysalary(DataTable commonSalaryEmployee)
{
// display result using commonSalaryEmployee DataTable
}

Advertisements

About Gokul Dahal, Nepal

Software Engineer, Freelancer, Design and Develop web applications,Software Developer Nepal, FreeLancer Nepal Contact : gokuldahal@gmail.com
This entry was posted in ASP.NET, C# and tagged , , , , , , . Bookmark the permalink.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s