Vb.net 使用数据库确定时间是否在t1和t2之间

Vb.net 使用数据库确定时间是否在t1和t2之间,vb.net,Vb.net,每当我启动程序时,我想使用datetimepicker确定combobox中的时间是否在我的开始时间和结束时间和日期之间,它表示表保留已由其他用户打开 这是我的密码: Sub checkingsched() cn.Close() cn.Open() cmd = New OleDbCommand("SELECT * FROM mechanics Where Mechanic_ID = " & cmbmechanic.Text & ";", cn) d

每当我启动程序时,我想使用datetimepicker确定combobox中的时间是否在我的开始时间和结束时间和日期之间,它表示表保留已由其他用户打开

这是我的密码:

Sub checkingsched()
    cn.Close()
    cn.Open()
    cmd = New OleDbCommand("SELECT * FROM mechanics Where Mechanic_ID = " & cmbmechanic.Text & ";", cn)
    dr = cmd.ExecuteReader
    If (dr.Read()) = True Then
        dt.Clear()
        da = New OleDbDataAdapter("SELECT Start_Time, End_Time, DateR  FROM Reserve where Mechanic_ID = " & cmbmechanic.Text & ";", cn)
        da.Fill(dt)
        cn.Close()
        Dim st As Date = (Format(("Start_Time"), "Short Time"))
        Dim et As Date = (Format(("End_Time"), "Short Time"))
        Dim dtt As Date = (Format(DateTime.Today, "Short Date"))
        Dim dtp As Date = (Format(DateTimePicker1.Value, "Short Date"))
        Dim tm As Date = (Format(DateTime.Today, "Short Time"))

        If cmbtos.Text = (tm.Ticks >= et.Ticks And tm.Ticks <= st.Ticks) And dtp = (dr(dt.Rows(0)("DateR"))) Then
            MessageBox.Show("Cannot Reserve in this time. Mechanics is on reserve in that time or working that time")
            itemsoftos()


        End If
        cn.Close()



    End If
    cn.Close()
End Sub

您正在使用哪个数据库?因为MS-SQL和其他语言有一个适合于此的中间表达式:where[DateField]在'StartDate'和'EndDate'之间,尽管听起来您可能会问为什么您会得到一个正在使用的表错误?问题是什么?所有这些cn.Open和cn.Close语句都没有cn.Dispose的迹象,你应该会遇到问题。相反,仅当需要在Using语句中使用连接变量时,才创建连接变量。相应的终端使用将负责清洁和自动地处理连接。