Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with simple SQL plus query in VB.NET

Options
  • 26-04-2013 3:55pm
    #1
    Registered Users Posts: 12,502 ✭✭✭✭


    Hey,
    I'm doing a rental system where I'm trying to load values from my "RentEnd" field in my Rental's table where today's date is greater than than the date in the RentEnd field. It's basically to find any cars that are late and are overdue to be returned.
    I've tried a few queries but not having any joy. In my VB, I have a label called lblDate which is set to today's date.
    lblDate.Text = FormatDateTime(Today, DateFormat.ShortDate)
    

    This is an attempt at one of my SQL statements
    strSQL = "SELECT * FROM Rentals WHERE RentEnd < '" + lblDate.Text + " '"
    
    Thanks!


Comments

  • Registered Users Posts: 2,022 ✭✭✭Colonel Panic


    "not having any joy" is not an error message.

    What DB are you working with? Have you tried querying the data outside of your app? Does the query in your code throw any exceptions? Does it return any results?


  • Registered Users Posts: 7,501 ✭✭✭BrokenArrows


    1. You cant always compare a text representation of a date to a Date column in the database.

    Reason:

    lblDate.Text for example might be equal to "2013-05-31"
    But the Date field in the database might be "2013-05-31 00:00:00.000000"

    Different databases handle date comparisons differently so its best you advise what database you are using.


  • Registered Users Posts: 291 ✭✭Seridisand


    I might be wrong(happened once before) but I thought vb.net SQL was formatted like this(with & for variables)
    "strSQL = "SELECT * FROM Rentals WHERE RentEnd < '" & lblDate.Text & "'"
    


  • Closed Accounts Posts: 2,930 ✭✭✭COYW


    Seridisand wrote: »
    I might be wrong(happened once before) but I thought vb.net SQL was formatted like this(with & for variables)
    "strSQL = "SELECT * FROM Rentals WHERE RentEnd < '" & lblDate.Text & "'"
    

    You are correct again on this occasion. :D

    OP, can you post up your a code block and the error message you are receiving. Below is a link to a basic tutorial on retrieving records from SQL Server using VB.Net.

    SQL & VB.Net


  • Registered Users Posts: 12,502 ✭✭✭✭siblers


    Thanks for the replies, I'll get some code up when I'm in college in Monday. All my other queries are working, I'm able to load in Dates, amend dates, record dates etc but this is the one thing I can't seem to do.


  • Advertisement
Advertisement