0

Hi,

i am trying to extract values based on range of dates.
Why i am getting this error

Invalidcastexception was unhandeled
Conversion from string "SELECT * FROM TBLRequest where T" to type 'Long' is not valid.

for below string
FlexString = "SELECT * FROM TBLRequest where TBLRequest.PrDate >='" & Date.Parse(TxtDateFrom.Text) And "TBLRequest.PrDate<='" & Date.Parse(TxtDateTo.Text) & "'"
Thanks

Edited by PM312

3
Contributors
4
Replies
23
Views
2 Years
Discussion Span
Last Post by danielgr
0

The error is related to your SQL query itself. It seems to be implying that the variable you are storing the string in is set to be a long variable.
What is the actual code around the problem?

0

** Public FlexString As String**

there is no issue for below code
** FlexString = "Select * from TBL_PR order by PRNO"**

errar occures only for between for e.g
FlexString = "SELECT * FROM TBLRequest where TBLRequest.PrDate between'" & Date.Parse(TxtDateFrom.Text) And Date.Parse(TxtDateTo.Text) & "'"

0

The error says you are trying to put a string into a long. That should be enough to track down the cause.
Although your SQL query doesn't look right. Don't you want quotes around the 'AND'? Otherwise you're using it as the boolean operator (I think, my VB>net is rusty)

0

FlexString = "SELECT * FROM TBLRequest where TBLRequest.PrDate between '" & Date.Parse(TxtDateFrom.Text) & "' And '" & Date.Parse(TxtDateTo.Text) & "'"

Although if the fields are dates in the database you could probably use (depending on the database engine):

FlexString = "SELECT * FROM TBLRequest where TBLRequest.PrDate between " & Date.Parse(TxtDateFrom.Text) & " And " & Date.Parse(TxtDateTo.Text)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.