Locked VBNEt2008 SQL STRING DATE BETWEEN

  • Sunday, December 25, 2011 9:38 PM
     
     

    Hullo Good Guy,

    I am using VBNEt2008 to develop Window Application using SQL SERVER 2000 and SQL STRING with DATE BETWEEN LOGIC and it's not working with these error messge:

    Error Message :

    Invalid column name “strFromDate

    Invalid column name “strToDate

    Here are the overall coding:

    Dim strFromDate as string = Me.TxtDateFrom.text.to.shortDateString

    Dim strToDate as string = Me.TxtDateTo.text.to.shortDateString

     

     

    Private Sub FLoadDataGridView()

      Dim strsql As String = Nothing

      strsql &= "Select OrderID, "

      strsql &= "convert(varchar(10), OrderDate, 103) as [OrderDate], "

      strsql &= "Convert(numeric(10,2), Discount) as [Discount], "

      strsql &= "convert(numeric(10,2), ExtendedPrice) as [ExtendedPrice], "

      strsql &= "convert(numeric(10,2), Freight) as [Freight] "

      strsql &= "From TblInvoices where CustomerID = '" & strcustID & "'"

      strsql &= "And (OrderDate between strFromDate and strToDate) "

      strsql &= "Order by OrderID, OrderDate"

     

    End sub

    Please help me. I desperately need your help with the coding same of DATE BETWEEN in the SQL STRING

    Thank you very much for helping me.

    Cheers,

    Lennie

     


    Thank you very Much, Have a Good Day. Cheers, Lennie

All Replies

  • Friday, January 13, 2012 7:19 PM
     
     Proposed Answer

    Hi Tee,

    There is a problem in the string concatination, please correct this as shown below. It should solve.

    Change this line of Code from:

    strsql &= "And (OrderDate between strFromDate and strToDate) "

    to:

    strsql &= "And (OrderDate between " & strFromDate & " and " & " strToDate) "

    The syntax for getting date BETWEEN is as shown below example.

    SELECT

    * FROM Log WHERE Timestamp BETWEEN '20011212' AND

     -Mohammed Ghouse Ibne Barq Kadapavi
    http://www.ProgrammersVision.blogspot.com
    https://sites.google.com/site/BarqKadapavi
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful.

    '20020105'

    • Edited by Ghouse Barq Friday, January 13, 2012 7:19 PM
    • Proposed As Answer by Ghouse Barq Friday, January 13, 2012 7:19 PM
    •  
  • Thursday, February 02, 2012 9:09 AM
     
     

    Hello,

    Wrap both you dates in quotes like this and let me know

    strsql &= "And (OrderDate between " & strFromDate & " and " & " strToDate) "