Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Convert ISingleResult to List or DataTable in C#

In this article, I will explain you how to Convert Isingleresult to List and DataTable using C#.

Related Articles

  1. What is LINQ to SQL and how to create LINQ to SQL class in C# with example for beginners
  2. LINQ to SQL: GridView select, insert, update and delete using C# with asp.net
  3. LINQ to SQL: Calling stored procedure with select, insert, update and delete in asp.net
  4. Insert, update, delete, crud operation in asp.net gridview using stored procedure

Converting ISingleResult to List

Below is the code to which will Convert Isingleresult to List type in C#.

EmployeeDataContext employeeDbContext = new EmployeeDataContext();
ISingleResultusp_EmployeeResult> result = employeeDbContext.usp_Employee();
 
System.Collections.Generic.ListEmployee> emp = new ListEmployee>();
 
foreach (usp_EmployeeResult employee in result)
{
emp.Add( new Employee { Id=employee.Id,Name= employee.Name,Gender= employee.Gender,Salary=employee.Salary});
}
if (emp.Count > 0)
{
grdEmployee.DataSource = emp;
grdEmployee.DataBind();
}

Converting ISingleResult to DataTable

Below is the code to which will convert ISingleResult to DataTable in C#.

EmployeeDataContext employeeDbContext = new EmployeeDataContext();
ISingleResultusp_EmployeeResult> result = employeeDbContext.usp_Employee();
 
DataTable emp = new DataTable();
emp.Columns.Add("Id", typeof(Int32));
emp.Columns.Add("Name", typeof(string));
emp.Columns.Add("Gender", typeof(string));
emp.Columns.Add("Salary", typeof(Int32));
foreach (usp_EmployeeResult employee in result)
{
emp.Rows.Add(employee.Id, employee.Name, employee.Gender, employee.Salary);
}
if (emp.Rows.Count > 0)
{
grdEmployee.DataSource = emp;
grdEmployee.DataBind();
}


This post first appeared on ASPArticles, please read the originial post: here

Share the post

Convert ISingleResult to List or DataTable in C#

×

Subscribe to Asparticles

Get updates delivered right to your inbox!

Thank you for your subscription

×