По правде говоря, ваш оператор Select не имеет особого смысла для меня, но вот код, который вы можете использовать для выполнения ваших операторов SQL. По крайней мере, это даст вам образец для подражания. Вам нужно будет проверить типы данных в базе данных и соответственно скорректировать код.
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim RecordCount As Integer
'Keep your data objects local so you can be sure they are closed and disposed.
' A Using...End Using block ensures this even if there is an error
Using cn As New OleDbConnection("Your Connection String")
'Pass the command text and the connection directly to the constructor of the command
'Always use Parameters to avoid Sql injection
'If all you need is a count of records then ask for Count no all the data
Using scmd As New OleDbCommand("Select Count(*) From deptsched where [dtimein] <= @TimeIn And [dtimeout] >= @TimeOut;", cn) ' #" & combo1.text & "# and#" & combo2.text "# ")
scmd.Parameters.Add("@TimeIn", OleDbType.Date).Value = CDate(combo1.Text)
scmd.Parameters.Add("@TimeOut", OleDbType.Date).Value = CDate(combo2.Text)
cn.Open()
RecordCount = CInt(scmd.ExecuteScalar)
End Using
End Using
If RecordCount > 0 Then
MessageBox.Show("conflict")
Exit Sub
End If
Using cn As New OleDbConnection("Your Connection String")
Using cmds As New OleDbCommand("insert into deptsched values(@Field1, @Field2);", cn)
cmds.Parameters.Add("@Field1", OleDbType.VarChar).Value = c1.text
cmds.Parameters.Add("@Field2", OleDbType.VarChar).Value = c2.text
cn.Open()
cmds.ExecuteNonQuery()
End Using
End Using
MessageBox.Show("Save")
End Sub