Wednesday, February 23, 2011

Get DataTable From Linq query

Here code example



public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query)
{

if (query == null)
{
 throw new ArgumentNullException("query");
}

 IDbCommand cmd = ctx.GetCommand(query as IQueryable);
 SqlDataAdapter adapter = new SqlDataAdapter();
 adapter.SelectCommand = (SqlCommand)cmd;
 DataTable dt = new DataTable("sd");

try
{
 cmd.Connection.Open();
 adapter.FillSchema(dt, SchemaType.Source);
 adapter.Fill(dt);
}

finally
{
 cmd.Connection.Close();
}

 return dt; 

} 

No comments:

Post a Comment

TinyMCE Insert/Edit link not editable

 To fix this add  e.stopImmediatePropagation()  as below. $(document).on('focusin', function (e) {             if ($(e.target).close...