Question How to conflict time?

joseph27

New member
Joined
Jun 8, 2019
Messages
1
Programming Experience
Beginner
VB.NET:
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    Dim RecordCount As Integer

    Using cn As New OleDbConnection("Your Connection")
        Using scmd As New OleDbCommand("Select Count(*) From deptsched where [dtimein] <= @TimeIn And [dtimeout] >= @TimeOut;", cn)
            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

please help me to conflict time sample;
7:00-8:00 it will save but when i input 7:30-8:30 it also save but it is already conflict with the first input.
can u help me find a way?
 
Last edited by a moderator:
Look at your comparison. Of course it doesn't work the way you want because those criteria require that the new interval falls completely within the existing one, rather than just some part of it overlapping. Give some thought to what constitutes the correct criteria to test. Pick up a pen and paper and actually draw the different possibilities if you need to and then use criteria that cover all of them. I'll give you a clue: there will be four individual criteria and you will need to use both AND and OR operators.
 
Back
Top