简体   繁体   中英

using DATE in sql statement

I need some help! I have been searching for the answer for this but nothing I come across and try seem to work! Keep in mind I am new to programming and I'm a first time poster on here! I would appreciate any help and feedback!

I am creating a simple form that will track the current time a user clicks the start button and also a stop button. I am doing this in VB.NET and using Access as my database. The user logs in with an id # and their password and then are prompted to press 1 of 2 buttons: either start or stop. When they click start, their id #, name, and the current time is added to a table in access.

The issue I am having is when they click the stop button. When stop is clicked, it needs to check the database and see if a start time has been logged for that user by their id # on the same day they are clicking end.

ex: user clicks start at 9am, clicks end at 10am = end time is logged in the database. user clicks end without clicking start prior to clicking end = pop-up error message "start time was not entered"

This is currently what I have for this portion of my project:

Dim tdate As String

tdate = Date.Today

'connect to database
Using sr As StreamReader = New StreamReader("C:\DatabaseFile1.txt")
    Dim line As String

    line = sr.ReadLine()
    Reading_Line = CStr(line)
    Console.WriteLine(line)
 End Using


Database_Full_Path = Reading_Line

Cn = New ADODB.Connection

With Cn
    .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Database_Full_Path
    .Open()
End With



selstr2 = "SELECT Log.LastName, Log.FirstName, Log.IDnumber, Log.StartBreak, Log.EndBreak "
selstr2 = selstr2 & "FROM Log Log "
selstr2 = selstr2 & "WHERE ( Log.StartBreak = " & tdate & ") AND ( Log.IDnumber = " & id_F & ") "

It is adding all the information to my database, but is not properly checking if a start time has already been entered for the current date by user id #.

try this (adding single quote around the date):

selstr2 = "SELECT Log.LastName, Log.FirstName, Log.IDnumber, Log.StartBreak, Log.EndBreak "
selstr2 = selstr2 & "FROM Log Log "
selstr2 = selstr2 & "WHERE ( Log.StartBreak = '" & tdate & "') AND ( Log.IDnumber = " & id_F & ") "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM