简体   繁体   English

在SQL语句中使用DATE

[英]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. 我在VB.NET中这样做,并使用Access作为我的数据库。 The user logs in with an id # and their password and then are prompted to press 1 of 2 buttons: either start or stop. 用户使用ID号和密码登录,然后提示他们按2个按钮中的1个:启动或停止。 When they click start, their id #, name, and the current time is added to a table in access. 当他们单击开始时,其ID号,名称和当前时间将添加到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. 单击“停止”后,它需要检查数据库,并查看在单击结束的同一天,该用户的ID#是否已记录该用户的开始时间。

ex: user clicks start at 9am, clicks end at 10am = end time is logged in the database. 例如:用户点击开始于上午9点,点击结束于上午10点=结束时间记录在数据库中。 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 #. 它将所有信息添加到我的数据库中,但是没有正确检查是否已经通过用户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 & ") "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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