cool

public static DataSet LambdaGetRowFromTitle(string sTitle)

{

MoviesDataContext db = new MoviesDataContext();

var q = from movies in db.Movies

where movies.Title == sTitle

select new { movies.Title, movies.Description, movies.DateAdded };

DataTable dt = ToDataTable(db,q); // workaround as no linq to sql returns table!

DataSet ds = new DataSet();

ds.Tables.Add(dt);

return ds;

}

 

 

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

{

// from the web

// http://www.c-sharpcorner.com/UploadFile/VIMAL.LAKHERA/LINQResultsetToDatatable06242008042629AM/LINQResultsetToDatatable.aspx

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;

}

Advertisements
This entry was posted in Uncategorized. 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