Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. How to convert a field in a LINQ query

How to convert a field in a LINQ query

Scheduled Pinned Locked Moved LINQ
questioncsharpcssdatabaselinq
3 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hardus Lombaard
    wrote on last edited by
    #1

    One of the fields in my LINQ query is called 'DiaryDate'. This is a DateTime field. I want to convert it to a string in the format "dd/MM/yyyy" before I bind it to the grid (ugrdCases). How can I do this?

    var query = from c in this.BL.Policy.Cases
    select new
    {
    c.Value.CaseNumber,
    c.Value.TypeDescription,
    c.Value.AreaOfLawDescription,
    c.Value.DiaryDate,
    c.Value.ReportedDate,
    c.Value.StatusDescription,
    c.Value.LegalAdvisor.FirstName,
    c.Value.LegalAdvisor.BranchDescription,
    };
    ugrdCases.DataSource = null;
    ugrdCases.DataBind();
    ugrdCases.DataSource = query;
    ugrdCases.DataBind();

    S 1 Reply Last reply
    0
    • H Hardus Lombaard

      One of the fields in my LINQ query is called 'DiaryDate'. This is a DateTime field. I want to convert it to a string in the format "dd/MM/yyyy" before I bind it to the grid (ugrdCases). How can I do this?

      var query = from c in this.BL.Policy.Cases
      select new
      {
      c.Value.CaseNumber,
      c.Value.TypeDescription,
      c.Value.AreaOfLawDescription,
      c.Value.DiaryDate,
      c.Value.ReportedDate,
      c.Value.StatusDescription,
      c.Value.LegalAdvisor.FirstName,
      c.Value.LegalAdvisor.BranchDescription,
      };
      ugrdCases.DataSource = null;
      ugrdCases.DataBind();
      ugrdCases.DataSource = query;
      ugrdCases.DataBind();

      S Offline
      S Offline
      Syed Mehroz Alam
      wrote on last edited by
      #2

      Hi, This should be done on your GridView control using the DataFormatString property. Regards,

      Syed Mehroz Alam My Blog | My Articles
      Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

      B 1 Reply Last reply
      0
      • S Syed Mehroz Alam

        Hi, This should be done on your GridView control using the DataFormatString property. Regards,

        Syed Mehroz Alam My Blog | My Articles
        Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein

        B Offline
        B Offline
        BechBej
        wrote on last edited by
        #3

        The string.format(IFormatprovider, string, object) overload method could help you format you date as you wish take a look on that link http://msdn.microsoft.com/en-us/library/1ksz8yb7.aspx[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups