none
Select Date throwing error. RRS feed

  • Question

  •  

    Time(smalldatetime) is a column in tableuser

    var RT = from m in context.tableUser

     

    where

    m.UserId.Equals(User)

     

    select m.Time.Value.ToString("dd-MMM-yyyy"

    );

    gv.DataSource = RT;

    gv.DataBind();

    ERROR :

    LINQ to Entities does not recognize the method 'System.String ToString(System.String)' method, and this method cannot be translated into a store expression.



    Thursday, September 22, 2011 5:56 AM

Answers

  • Hi again,

    If you want an string, you can perform something like this when formatting dates:

    strTime = (!m.Time.HasValue) ? "" : String.Format("{0}:d-MMM-yyyy ",m.Time.Value),
    


    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Thursday, September 22, 2011 8:45 AM

All replies

  • Hi,

    Remember that your query would be translated to SQL so the date formatting you tried to perform is not supported. You should get your required data first and then try to format the date as you need.

    Anyway, is your Time property is nullable, you should check this before using m.Time,Value

     

    Best regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    • Edited by JA Reyes Thursday, September 22, 2011 8:18 AM
    Thursday, September 22, 2011 8:17 AM
  • yes it is null...how to handle it !!!

    More over how can i compare smalldatetime column to var RT......Kindly help as soon as possible ... it is urgent !!!

    Thursday, September 22, 2011 8:32 AM
  • Hi again,

    If you want an string, you can perform something like this when formatting dates:

    strTime = (!m.Time.HasValue) ? "" : String.Format("{0}:d-MMM-yyyy ",m.Time.Value),
    


    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solución de esta pregunta te ha sido útil.
    Thursday, September 22, 2011 8:45 AM
  • thanx a ton JA Reyes.
    Monday, September 26, 2011 10:30 AM