如何从我的数据库中检索时间。 [英] How Do I Retrieve Times From My Database.

查看:163
本文介绍了如何从我的数据库中检索时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在我的数据库中有一个名为open_hours的表,其中包含一周中每一天的场地的开放时间和结束时间(保存为类型时间)。我正在预订系统,所以我希望能够检查用户输入的预订时间是否在营业时间内。

Hi, so i have a table in my database called open_hours, containing the open time and closing time (saved as type time) of a venue for each day of the week. Im making a booking system so i want to be able to check if the booking times entered by the user are within the open hours.

Try
           mysqlconn.Open()
           query = "SELECT* FROM open_hours WHERE day='" & Datetimepicker1.Value.DayOfWeek.ToString & "'"
           MsgBox(query)
           command = New MySqlCommand(query, mysqlconn)
           reader = command.ExecuteReader
           While reader.Read()
               If start_time.value < reader.GetDateTime("open_time") Or end_time.value > reader.GetDateTime("close_time") Then
                   errors.Enqueue("The booking must be within the opening times")
               End If
           End While
           mysqlconn.Close()
       Catch ex As Exception
           MsgBox(ex.Message)
       Finally
           mysqlconn.Dispose()
       End Try





所以这是我到目前为止,但是,当我点击按钮检查预订可用性时,我收到一条错误消息说无法使用 o将MYSQL日期/时间值转换为system.datetime。

现在,我已经使用Google搜索此错误消息和一般解决方案,如果要将Convert Zero Datetime = True添加到连接字符串。





So this is what i have so far however, when i click the button to check the bookings availabliity, i get an error message say "Unable to convert MYSQL date/time value to system.datetime".
Now, i've googled this error message and the general solution if to add Convert Zero Datetime=True to the connection string.

mysqlconn.ConnectionString = "Server=localhost;userid=root;password=root;database=comp4;Convert Zero Datetime=True"





我这样做,我确实得到open_time的值,但它只是00:00:00。

我的开放时间都不是00:00:00所以我不明白最新情况。

请帮忙,这让我发疯了!



When i do this, i do get a value for the open_time, but its just 00:00:00.
None of my open times are 00:00:00 so i dont understand whats going on.
Please help, this is driving me crazy!!

推荐答案

也许你应该考虑返回的内容更具体的是 TimeSpan 而不是 DateTime



如果您使用以下内容怎么办?

Maybe you should consider that what is returned is more specific of a TimeSpan rather of a DateTime?

What if you use:
If start_time.value < reader.GetTimeSpan("open_time") Or end_time.value > reader.GetTimeSpan("close_time") Then
   errors.Enqueue("The booking must be within the opening times")
End If







希望这会有所帮助。祝你好运:)


?

Hope this helps. Good luck :)


这篇关于如何从我的数据库中检索时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆