Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I was facing Error when I debug it.
Can I know anything I did wrong ???
DataBase: PromoEvent_From and PromoEvent_To Both are DateTime Data Type.


VB
Dim wherestring As String = "it.[Status] = True"
        Dim gotError As Boolean = False

        If txtPromoEventFrom.Text = "" And txtPromoEventTo.Text = "" Then
            MsgBox("Division code cannot be blank")
            gotError = True
        Else
            If txtPromoEventFrom.Text <> "" Then
                wherestring += " AND it.[PromoEvent_From] >= " + DateTime.Parse(txtPromoEventFrom.Text) 
                wherestring += " AND it.[PromoEvent_From] <= " + DateTime.Parse(txtPromoEventFromTo.Text)
            End If
            If txtPromoEventTo.Text <> "" Then
                wherestring += " AND it.[PromoEvent_To] >= " + DateTime.Parse(txtPromoEventTo.Text) + ""
                wherestring += " AND it.[PromoEvent_To] >= " + DateTime.Parse(txtPromoEventToTo.Text) + ""

            Else

            End If

            If gotError = False Then
                EntityDataSource1.Where = wherestring
            End If
        End If



The following Msg is Error Box Msg when I Run:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The argument types 'Edm.DateTime' and 'Edm.Int32' are incompatible for this operation. Near greater than or equals expression, line 6, column 45.

Posted

1 solution

After read your code what I understand, you are trying to make SQL string. In sql string final output you miss "'" for every date part. Here is the correct code. hope this is help you.

Dim wherestring As String = "it.[Status] = True"
       Dim gotError As Boolean = False

       If txtPromoEventFrom.Text = "" And txtPromoEventTo.Text = "" Then
           MsgBox("Division code cannot be blank")
           gotError = True
       Else
           If txtPromoEventFrom.Text <> "" Then
               wherestring += " AND it.[PromoEvent_From] >= '" + DateTime.Parse(txtPromoEventFrom.Text) + "' "
               wherestring += " AND it.[PromoEvent_From] <= '" + DateTime.Parse(txtPromoEventTo.Text) + "' "
           End If
           If txtPromoEventTo.Text <> "" Then
               wherestring += " AND it.[PromoEvent_To] >= '" + DateTime.Parse(txtPromoEventFrom.Text) + "'"
               wherestring += " AND it.[PromoEvent_To] >= '" + DateTime.Parse(txtPromoEventTo.Text) + "'"

           Else

           End If

           If gotError = False Then
               EntityDataSource1.Where = wherestring
           End If
       End If
 
Share this answer
 
Comments
Member 10230385 26-Aug-13 8:58am    
Hi, that is search button actually.
I just wan to convert txtPromoEventForm.Text to DateTime.
Hasan Habib Surzo 26-Aug-13 9:06am    
it is not a problem where you use it. where you try to send datetime to sql string it must be in between '' like '26/08/2013' otherwise SQL not recognize it as datetime. also there are typing mistake in your code
wherestring += " AND it.[PromoEvent_To] >= " + DateTime.Parse(txtPromoEventToTo.Text) + ""

in this line you type txtPromoEventToTo.
Member 10230385 26-Aug-13 9:39am    
txtPromoEventToTo is right. no problem that is the id I set.
i try to use ur code. but show error.
i always get the following error:

Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException:
The argument types 'Edm.DateTime' and 'Edm.Int32' are incompatible for this operation. Near greater than or equals expression, line 6, column 45.
Hasan Habib Surzo 26-Aug-13 10:08am    
can you share your files?
Also please try date input as '01/Jan/2013' instead of '01/01/2013'
Member 10230385 26-Aug-13 21:44pm    
i think it problem when we convert it. Because i saw in the Error MSG.

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The argument types 'Edm.DateTime' and 'Edm.Int32' are incompatible for this operation. Near greater than or equals expression, line 6, column 45.

Why after convet not date time ??? is EDM.Int32 ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900