LinqDataSource + WhereParameter + incompatible data type

HI

I am using LinqDataSource to bind some data to Gridview

There are two Where parameters i am using to limit the records..
Unfortunately there both of them are DataTime values in the SQlToLinqobject..
But in the Text both they are in this text format... 10/10/2008

So as ASP.net is unable to implicitly convert or whatever reason it is throwing this exception out

 Operator '>=' incompatible with operand types 'DateTime?' and 'Object'


Attached is the code snippet
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="IVRStatsDataClassesDataContext"
                                Select="new (Customer_ANI, OperatorID, OperatorName, Operator_Type, Operator_ANI, OpCall_OutdialStart, OpCall_OutdialEnd, OpCall_PickupLag, OpCall_TalkDuration, OpCall_Status)"
                                TableName="CustomerServiceCalls" 
                                
                                Where="ServiceIdentifier == @ServiceIdentifier &amp;&amp; OpCall_Status != @OpCall_Status &amp;&amp; CS_IndialStart &gt;= @CS_IndialStart &amp;&amp; CS_IndialStart &lt;= @CS_IndialEnd" OnSelecting="LinqDataSource1_Selecting" 
                                >
                                <WhereParameters>
                                    <asp:Parameter DefaultValue="Skyecloud Customer Service" Name="ServiceIdentifier"
                                        Type="String" />
                                    <asp:Parameter DefaultValue="Not Transferred to Operator" Name="OpCall_Status" Type="String" />
                                    <asp:ControlParameter ControlID="tb_startDate" Name="CS_IndialStart" PropertyName="Text"
                                        Type="DateTime" />
                                    <asp:ControlParameter ControlID="tb_endDate" Name="CS_IndialEnd" PropertyName="Text"
                                        Type="DateTime" />
                                    
                                </WhereParameters>
                            </asp:LinqDataSource>

Open in new window

justin_smithAsked:
Who is Participating?
 
PockyMasterConnect With a Mentor Commented:
well, it works normally in linq syntax, have not tried linq in asp.net I must admit.
but yeah, in the where part. You might have to play with the DateTime.Parse (maybe provide format or culture settings, just like what you would do in non asp.net code)
<asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="IVRStatsDataClassesDataContext"
                                Select="new (Customer_ANI, OperatorID, OperatorName, Operator_Type, Operator_ANI, OpCall_OutdialStart, OpCall_OutdialEnd, OpCall_PickupLag, OpCall_TalkDuration, OpCall_Status)"
                                TableName="CustomerServiceCalls" 
                                
                                Where="ServiceIdentifier == @ServiceIdentifier && OpCall_Status != @OpCall_Status && CS_IndialStart >= DateTime.Parse(@CS_IndialStart) && CS_IndialStart <= DateTime.Parse(@CS_IndialEnd)" OnSelecting="LinqDataSource1_Selecting" 
                                >

Open in new window

0
 
PockyMasterCommented:
use DateTime.Parse around your text variable to parse the datetime.
Your code is a bit messed up by the tags, but I suppose it's:
 CS_IndialStart  >= DateTime.Parse(@CS_IndialStart )
0
 
justin_smithAuthor Commented:
you mean in the Where="" part?

That means i could even add a day if need (i can use this for end date)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.