Please let us know if you still facing any problem then specify your next generated problem at here.
If provided solution works with your issue then please mark as answer so that people can bazzing this theads. and more thing if you have implmented any other solution in your problem then also please add this solution over here so that other person can use
that code.
My Tech Blogs MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
razaussamad
Member
32 Points
18 Posts
How to concatenate multiple columns through LINQ for a Datasoucre
Jun 30, 2011 09:31 AM|LINK
hello!
I already worked on .NET C# and ASP.NET, but I am fresh comer in LINQ.
My problem is, i want to Concatenate multiple colums (new dervied columns) of a single table in LINQ,
and then bind the LINQ result to some BindingSource (stockBindingSource).
And my DatagridView bound by BindingSource.
like this:
NorthwindDataContext db = new NorthwindDataContext ();
Object query = from q in db.Stocks select new {q.StockID, q.Amount*1.05};
stockBindingSource.DataSource = query;
but system generates error of type mismatching.
anyone can solve this
Kindly reply me
regards
Raza us Samad
Linq
Mastan Oli
Contributor
5088 Points
998 Posts
Re: How to concatenate multiple columns through LINQ for a Datasoucre
Jun 30, 2011 09:39 AM|LINK
change your code like
var query = from q in db.Stocks select new { StockID = q.StockID, Amount = q.Amount*1.05 };Linq
playingOOPS | மெய்ப்பொருள் காண்பதறிவு
Mark as Answer If you find helpful
razaussamad
Member
32 Points
18 Posts
Re: How to concatenate multiple columns through LINQ for a Datasoucre
Jun 30, 2011 09:50 AM|LINK
i already tried this one but . .. the error is:
"Cannot bind to the property or column Commision on the DataSource.
Parameter name: dataMember"
my table contains a colum of "Commission". but i did not work over that column in above statement.
amitpatel.it
Star
7956 Points
1865 Posts
Re: How to concatenate multiple columns through LINQ for a Datasoucre
Jun 30, 2011 09:56 AM|LINK
Below is the example of two columns concatation
ViewBag.AssignedUserID = new SelectList((from s in dbUsers.Users.Where(q => q.CompanyID == ApplicationSession.LoggedInCompanyID && q.UserTypeID == UserType && q.IsActive == true).ToList<Users>() select new { ID = s.ID, FullName = s.FirstName + " " + s.LastName }), "ID", "FullName");This code I have example of string concate you can do any arithmatic operation as well. just simply multiple column in palce of concate two string.
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to concatenate multiple columns through LINQ for a Datasoucre
Jul 02, 2011 02:08 AM|LINK
Hello:)
var query = from q in db.Stocks
select new
{ StockID = q.StockID, Amount = q.Amount*1.05
};
I think this code is right. So What have you written there?
Thx
amitpatel.it
Star
7956 Points
1865 Posts
Re: How to concatenate multiple columns through LINQ for a Datasoucre
Jul 02, 2011 05:29 AM|LINK
Please let us know if you still facing any problem then specify your next generated problem at here.
If provided solution works with your issue then please mark as answer so that people can bazzing this theads. and more thing if you have implmented any other solution in your problem then also please add this solution over here so that other person can use that code.
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
razaussamad
Member
32 Points
18 Posts
Re: How to concatenate multiple columns through LINQ for a Datasoucre
Jul 16, 2011 07:22 PM|LINK
thanks to all
actually the problem is . . . LINQ "select new" clause not working with Binding Source while in edit mode :)
because we are getting derived columns and those columns are not available in database!!
i solved this issue!!
again thanks to all