Date conversion in typed list

Posts   
 
    
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 13-Jul-2012 15:31:20   

LLBLGen 3.5 .net framework 4.0 C# windows application LLBLgen run time framework

Dear Support team,

I am trying to convert date format in typed list based on example given in http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=16740. But I get an error "An exception was caught during the execution of a retrieval query: Argument data type nvarchar is invalid for argument 3 of convert function.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception". If I remove the line billdate.SetExpression, it just works fine

public static DataTable returnGuestregistrationReverseload(string Date, string Id)
        {
            
            try
            {
                string regndate = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(Date).Date);
                var guestregistration = new TlguestRegistrationTypedList();
                EntityField billdate = GuestregnheaderFields.Regndate;

                [b]billdate.SetExpression(new DbFunctionCall("CONVERT(VARCHAR, {0},{1})", new object[] { GuestregnheaderFields.Regndate,"103" }));
[/b]
                IPredicateExpression filter =
                    new PredicateExpression(billdate == regndate)
                        .AddWithAnd(new FieldCompareValuePredicate(GuestregnheaderFields.Guestregnheaderid,
                                                                   ComparisonOperator.Equal,
                                                                   Id));
                        
                guestregistration.Fill(0, null, true, filter);

                return guestregistration;


            
            }
            catch (Exception ex)
            {
                ErrorHandler.LogMessage(ex.Message + ex.StackTrace);
                throw;
            }
        
        }
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Jul-2012 02:09:21   

I'm not sure but I think it fails because the third function param is interpreted as a nvarchar and it's actually a constant. Try this:

billdate.SetExpression(new DbFunctionCall("CONVERT(VARCHAR, {0}, 103)", new object[] { GuestregnheaderFields.Regndate}));
David Elizondo | LLBLGen Support Team
shekar
User
Posts: 327
Joined: 26-Mar-2010
# Posted on: 14-Jul-2012 06:43:31   

daelmo wrote:

I'm not sure but I think it fails because the third function param is interpreted as a nvarchar and it's actually a constant. Try this:

billdate.SetExpression(new DbFunctionCall("CONVERT(VARCHAR, {0}, 103)", new object[] { GuestregnheaderFields.Regndate}));

Thanks, daelmo. It worked