Link to home
Start Free TrialLog in
Avatar of adskarcox
adskarcoxFlag for United States of America

asked on

Add row to DataSet Programmatically

Hello,

Let's say we generate this link-to-sql dataset for a grid:

var query = from c in customers
                    orderby c.FirstName
                    select c;

Grid1.DataSet = query;
Grid1.DataBind();

Open in new window


We need to programmatically add "Vince Vaughn" to this dataset in a manner that will allow him to be the top row in the grid.  

How would be accomplish this programmatically using C#? (i.e. programmatically add a row for Vince Vaughn to the dataset, and do so in a manner that this new row is "on the top", so that it will be the first row in the grid)

CUSTOMERS
ID     FirstName    LastName
1       John              Jones
2       Sally              Smith

Environment: C#.NET 4.0
Avatar of amarpal0102
amarpal0102
Flag of New Zealand image

ASKER CERTIFIED SOLUTION
Avatar of amarpal0102
amarpal0102
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adskarcox

ASKER

Thanks for posting.  The example you provided is interesting, but it only shows how to create a dataset from scratch, without any linq-to-sql input.

I need the linq-to-sql side of things to be able to fully understand how to do this.

Thanks again.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
roopeshreddy- thanks for posting that link that goes of linq-to-sql.

So far, amarpal0102 posted some links that cover how to create a dataset and add rows to it and roopeshreddy has posted a link that goes over linq-to-sql.  What I really need, however, is a code sample that merges the two.  

Here is my question:  How do I add a row to the query dataset listed in this code:

var query = from c in customers
                    orderby c.FirstName
                    select c;

Grid1.DataSet = query;
Grid1.DataBind();

Open in new window

I need someone to post some code, not links.  Thank you.