Sai Stuff to Developers

April 12, 2012

Adding a new record to an IQueryable variable

Filed under: LINQ — tosaik @ 7:09 am
Tags: ,

Hi All,

Recently working on one of my application using Linq, i need to fill the datagridview with selected rows and columns which i can get from querying a list of objects using Linq. Now for every result i need to add an additional static record to the grid view. for this i need to have this record as a last record for my selected IQueryable variable from LINQ result.  Let me show you through example what i said till now…


var varresult = from r in lstobject select new { COLUMN1 = r.Title, COLUMN2 = r.Price };

DataGridView1.datasource = varresult ;


Now i need to add a new static record (i.e.., new{COLUMN1=”Discount Price”, COLUMN2=10}) to the existing varresult object…

varresult  = varresult.ToList().Union(new[] { new{COLUMN1=”Discount Price”, COLUMN2=10}});

DataGridView1.datasource = varresult ;



thats it Now a last record will be what you want… Please note that the variables and there types should be same as result object had.

Hope this Helps u…


Happy Coding 🙂







Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Blog at

%d bloggers like this: