Date PROBLEM in VB.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kayclink
    New Member
    • Oct 2009
    • 4

    Date PROBLEM in VB.NET

    Hello, i am getting a problem to generate a report based on a date. iam using vb.net 2005 and SQL 2000. here is my code;
    [code=vbnet]
    myConnection = New SqlConnection(" Data Source=CALVIN20 09\DEV;Initial Catalog=TBFMS;I ntegrated Security=True;d atabase = TBFMS")
    MyCommand.Conne ction = myConnection

    'If Main.ManifestDa tagrid.Selected Rows.Count > 0 Then

    MyCommand.Comma ndText = "select *from Booking2 where BookingDate between convert(datetim e,'" & Format(Me.DateT imePicker1.Valu e, "dd/MM/yyyy") & "',103) AND ""convert(datet ime,'" & Format(Me.DateT imePicker1.Valu e.AddDays(1), "dd/MM/yyyy") & "',103"

    MyCommand.Comma ndType = CommandType.Tex t
    myDA.SelectComm and = MyCommand
    myDA.Fill(myDS, "Booking2")
    [/code]
    it gives an error: "Unclosed quotation mark before the character string 'convert(dateti me....and so on..

    please help
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well you are doing a lot of ' and " and "" in that string.
    I recomend switching to either a StringBuilder or a Parameter-ized command

    EDIT:
    Actually, just going through it I see a lot of missing characters.


    Try this:
    [code=vbnet]
    MyCommand.Comma ndText = string.Format(" select * from Booking2 where BookingDate between convert(datetim e,'{0}',103) AND convert(datetim e,'{1}',103)", Me.DateTimePick er1.Value.ToStr ing("dd/MM/yyyy"),Me.DateT imePicker1.Valu e.AddDays(1).To String("dd/MM/yyyy"))
    [/code]

    Comment

    Working...