DBFUNCTIONCAll using Compact Framework v2 and SQL Mobile 2005

Posts   
 
    
Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 05-Jan-2008 04:35:49   
        Dim fields As New ResultsetFields(5)
        fields.DefineField(HistoryFields.StartTime, 0, "Datee", "History")
        fields.DefineField(HistoryFields.StartTime, 1, "StartTime", "History")
        fields.DefineField(ExerciseFields.Name, 2, "ExerciseName", "Exercise")
        fields.DefineField(HistoryFields.Weight, 3, "Weight", "History")
        fields.DefineField(HistoryFields.WeightUnits, 4, "WeightUnits", "History")

        fields(0).ExpressionToApply = New DbFunctionCall("datepart", New Object() {"Month", "StartTime"}) **CAUSES ERROR**

        fields(0).ExpressionToApply = New DbFunctionCall("UPPER", New Object() {"Month"}) **WORKS FINE**


        Dim bucket As IRelationPredicateBucket = New RelationPredicateBucket()
        bucket.Relations.Add(ExerciseEntity.Relations.HistoryEntityUsingExerciseId, "Exercise", "History", JoinHint.Inner)

        Dim dynamicList As New Data.DataTable()

        Dim sorter As New SortExpression()
        sorter.Add(New SortClause(HistoryFields.StartTime, Nothing, SortOperator.Ascending, "History"))

        adapter.FetchTypedList(fields, dynamicList, bucket, 0, sorter, True)

Why am i getting an error when i try to call sql function? Sql mobile 2005 does support datepart.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Jan-2008 06:26:38   

Hi Anthony,

I think the problem is that _Datepart _function expect a literal non-string in the first parameter. If you send "Month" to the parameter, this will cause LLBLGen send it as a string parameter to the function, causing the problem. _UPPER _works coz it expect a string parameter and you just sent it.

So, this should works fine:

fields(0).ExpressionToApply = new DbFunctionCall("datepart(Month,{0})", new Object() {fields[1] })

If you just need only the month part, this should works too:

fields(0).ExpressionToApply = new DbFunctionCall("Month", new Object() { fields[1] })
David Elizondo | LLBLGen Support Team