Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6091459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:19:49+00:00 2026-05-23T12:19:49+00:00

Here is my LINQ Query: GridView.DataSource = from it in DataContext.Items where it.ThingId ==

  • 0

Here is my LINQ Query:

GridView.DataSource = from it in DataContext.Items
    where it.ThingId == thing.ThingId
    select new
    {
        it.Something,
        it.SomethingElse,
        it.AnotherSomething,
        Currency = String.Format("{0:C}", it.Decimal.ToString()), 
        //^--This is the line that needs to be converted to currency, this doesn't work--^
    };

The it.Decimal is returning a decimal in the form 12345.00 and I need to convert that to $12,345.00 when displayed in the gridview. What I have now doesn’t work, because a LINQ Query won’t recognize the String.Format function. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:19:50+00:00Added an answer on May 23, 2026 at 12:19 pm

    Just remove the ToString:

    Currency = String.Format("{0:C}", it.Decimal)
    

    You can also use this form:

    Currency = it.Decimal.ToString("C")
    

    If you pass it.Decimal.ToString() as a parameter to String.Format, it will be handled as a string, not a decimal, so it won’t be able to apply the currency format.


    EDIT: ok, so you have another problem… Don’t forget that a Linq to SQL (or Entity Framework) query is converted to SQL and executed by the database; the database doesn’t know String.Format, so it can’t be converted to SQL. You need to retrieve the “raw” result from the db, and then format it using Linq to Objects:

    var query = from it in DataContext.Items
        where it.ThingId == thing.ThingId
        select new
        {
            it.Something,
            it.SomethingElse,
            it.AnotherSomething,
            it.Decimal
        };
    
    GridView.DataSource = from it in query.AsEnumerable()
        select new
        {
            it.Something,
            it.SomethingElse,
            it.AnotherSomething,
            Currency = it.Decimal.ToString("C")
        };
    

    (Note the use of AsEnumerable to “switch” to Linq to Objects)

    Another option would be to give the raw decimal value to the GridView, and set the column’s DataFormatString property to “C”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my LINQ query: (from o in entities.MyTable orderby o.MyColumn select o.MyColumn).Distinct(); Here
Here's an example of the query I'm trying to convert to LINQ: SELECT *
here is my linq query: var test = from m in db.Members where m.UserId
Okay so here's the thing: I have a linq query which loads approx. 1000
My LINQ query is as follows Dim Query = From t In New XPQuery(Of
Here is a Linq query: Common.ProductType.ProductTypeEnum[] aCustomerProduct = (from customer in repositoryCustomer.GetAll().Where(cp => cp.Email
Here is a cut down version of my linq query; var list = from
I've got a LINQ query going against an Entity Framework object. Here's a summary
I'm trying to write a linq to object query in vb.net, here is the
I asked a question here about an Linq error that results from mixing Linq-To-SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.