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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with simple SQL plus query in VB.NET

  • 26-04-2013 02:55PM
    #1
    Registered Users, Registered Users 2 Posts: 12,784 ✭✭✭✭


    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, Registered Users 2 Posts: 2,055 ✭✭✭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, Registered Users 2 Posts: 7,529 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 12,784 ✭✭✭✭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