Adding a new record to an IQueryable variable

Adding a new record to an IQueryable variable

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…

Ex:

1.var varresult = from r in lstobject select new { COLUMN1 = r.Title, COLUMN2 = r.Price };
2. 
3.DataGridView1.datasource = varresult ;
4. 
5.DataGridView1.databind();

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

1.varresult  = varresult.ToList().Union(new[] { new{COLUMN1=”Discount Price”, COLUMN2=10}});
2. 
3.DataGridView1.datasource = varresult ;
4. 
5.DataGridView1.databind();

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
  • Please add 7 and 2 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Maheshkumar S Tiwari edited Original. Comment: Added tags and minor edit

Page 1 of 1 (1 items)