[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

LinqDataSource + WhereParameter + incompatible data type

Posted on 2008-11-17
3
Medium Priority
?
2,419 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:justin_smith
  • 2
3 Comments
 
LVL 14

Expert Comment

by:PockyMaster
ID: 23020355
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
 

Author Comment

by:justin_smith
ID: 23023356
you mean in the Where="" part?

That means i could even add a day if need (i can use this for end date)
0
 
LVL 14

Accepted Solution

by:
PockyMaster earned 2000 total points
ID: 23024537
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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question