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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
PockyMasterCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.