hi everyone! below i will be showing you the codes of my scheduling module for an enrollment system..my problem is that on how to set conflict

here is the code:

Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Public Class Scheduling
Dim con As OleDbConnection
Dim com As New OleDbCommand
Dim cmd As OleDbCommandBuilder
Dim ds As DataSet
Dim da As New OleDbDataAdapter
Dim lastrow As Integer
Dim myrow As Data.DataRow
Dim rid As OleDbDataReader

Private Sub Button2_Click(ByVal sEer As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    If ListView1.Items.Count <> 8 Then
        MsgBox("There must be eight subjects!", MsgBoxStyle.Information, "Warning")
    ElseIf ComboBox1.Text = "First Year" Then
        For i = 0 To ListView1.Items.Count - 1
            con = New OleDbConnection("Provider=Microsoft.ace.oledb.12.0;Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
            da.SelectCommand = New OleDbCommand("Select* from Schedulings", con)
            cmd = New OleDbCommandBuilder(da)
            If con.State = ConnectionState.Closed Then con.Open()
            ds = New DataSet
            da.Fill(ds, "Schedulings")
            ds.Tables("Schedulings").Rows.Add()
            lastrow = ds.Tables("Schedulings").Rows.Count - 1
            myrow = ds.Tables("Schedulings").Rows.Item(lastrow)
            myrow.Item("YearLevels") = ComboBox1.Text
            myrow.Item("Sections") = ComboBox3.Text
            myrow.Item("SectionNames") = TextBox9.Text
            myrow.Item("Adviser") = TextBox1.Text
            myrow.Item("SubjectTeacher") = TextBox2.Text
            myrow.Item("SubjectNames") = ComboBox7.Text
            myrow.Item("Days") = ComboBox2.Text
            myrow.Item("StartTimes") = ComboBox4.Text
            myrow.Item("EndTimes") = ComboBox5.Text
            myrow.Item("Rooms") = ComboBox6.Text
            ds.Tables("Schedulings").GetChanges()
            cmd.GetInsertCommand()
            da.Update(ds, "Schedulings")
            con.Close()
        Next i
        MsgBox("Registration Successful")
    ElseIf ComboBox1.Text = "Second Year" Then
        For i = 0 To ListView1.Items.Count - 1
            con = New OleDbConnection("Provider=Microsoft.ace.oledb.12.0;Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
            da.SelectCommand = New OleDbCommand("Select* from Schedulings", con)
            cmd = New OleDbCommandBuilder(da)
            If con.State = ConnectionState.Closed Then con.Open()
            ds = New DataSet
            da.Fill(ds, "Schedulings")
            ds.Tables("Schedulings").Rows.Add()
            lastrow = ds.Tables("Schedulings").Rows.Count - 1
            myrow = ds.Tables("Schedulings").Rows.Item(lastrow)
            myrow.Item("YearLevels") = ComboBox1.Text
            myrow.Item("Sections") = ComboBox3.Text
            myrow.Item("SectionNames") = TextBox9.Text
            myrow.Item("Adviser") = TextBox1.Text
            myrow.Item("SubjectTeacher") = TextBox2.Text
            myrow.Item("SubjectNames") = ComboBox8.Text
            myrow.Item("Days") = ComboBox2.Text
            myrow.Item("StartTimes") = ComboBox4.Text
            myrow.Item("EndTimes") = ComboBox5.Text
            myrow.Item("Rooms") = ComboBox6.Text
            ds.Tables("Schedulings").GetChanges()
            cmd.GetInsertCommand()
            da.Update(ds, "Schedulings")
            con.Close()
        Next i
        MsgBox("Registration Successful")
    ElseIf ComboBox1.Text = "Third Year" Then
        For i = 0 To ListView1.Items.Count - 1
            con = New OleDbConnection("Provider=Microsoft.ace.oledb.12.0;Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
            da.SelectCommand = New OleDbCommand("Select* from Schedulings", con)
            cmd = New OleDbCommandBuilder(da)
            If con.State = ConnectionState.Closed Then con.Open()
            ds = New DataSet
            da.Fill(ds, "Schedulings")
            ds.Tables("Schedulings").Rows.Add()
            lastrow = ds.Tables("Schedulings").Rows.Count - 1
            myrow = ds.Tables("Schedulings").Rows.Item(lastrow)
            myrow.Item("YearLevels") = ComboBox1.Text
            myrow.Item("Sections") = ComboBox3.Text
            myrow.Item("SectionNames") = TextBox9.Text
            myrow.Item("Adviser") = TextBox1.Text
            myrow.Item("SubjectTeacher") = TextBox2.Text
            myrow.Item("SubjectNames") = ComboBox9.Text
            myrow.Item("Days") = ComboBox2.Text
            myrow.Item("StartTimes") = ComboBox4.Text
            myrow.Item("EndTimes") = ComboBox5.Text
            myrow.Item("Rooms") = ComboBox6.Text
            ds.Tables("Schedulings").GetChanges()
            cmd.GetInsertCommand()
            da.Update(ds, "Schedulings")
            con.Close()
        Next i
        MsgBox("Registration Successful")
    ElseIf ComboBox1.Text = "Fourth Year" Then
        For i = 0 To ListView1.Items.Count - 1
            con = New OleDbConnection("Provider=Microsoft.ace.oledb.12.0;Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
            da.SelectCommand = New OleDbCommand("Select* from Schedulings", con)
            cmd = New OleDbCommandBuilder(da)
            If con.State = ConnectionState.Closed Then con.Open()
            ds = New DataSet
            da.Fill(ds, "Schedulings")
            ds.Tables("Schedulings").Rows.Add()
            lastrow = ds.Tables("Schedulings").Rows.Count - 1
            myrow = ds.Tables("Schedulings").Rows.Item(lastrow)
            myrow.Item("YearLevels") = ComboBox1.Text
            myrow.Item("Sections") = ComboBox3.Text
            myrow.Item("SectionNames") = TextBox9.Text
            myrow.Item("Adviser") = TextBox1.Text
            myrow.Item("SubjectTeacher") = TextBox2.Text
            myrow.Item("SubjectNames") = ComboBox27.Text
            myrow.Item("Days") = ComboBox2.Text
            myrow.Item("StartTimes") = ComboBox4.Text
            myrow.Item("EndTimes") = ComboBox5.Text
            myrow.Item("Rooms") = ComboBox6.Text
            ds.Tables("Schedulings").GetChanges()
            cmd.GetInsertCommand()
            da.Update(ds, "Schedulings")
            con.Close()
        Next i
        MsgBox("Registration Successful")
    End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    If ListView1.Items.Count > 1 Then
        TextBox9.Clear()
        TextBox1.Clear()
        TextBox2.Clear()
        ListView1.Items.Clear()
        ComboBox1.SelectedIndex = -1
        ComboBox3.SelectedIndex = -1
        ComboBox2.SelectedIndex = -1
        ComboBox4.SelectedIndex = -1
        ComboBox5.SelectedIndex = -1
        ComboBox6.SelectedIndex = -1
        ComboBox7.SelectedIndex = -1
        ComboBox8.SelectedIndex = -1
        ComboBox9.SelectedIndex = -1
        ComboBox27.SelectedIndex = -1
    Else
        MsgBox("Empty", MsgBoxStyle.Information, "Message")
    End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    If ComboBox1.Text = "First Year" Then
        If ComboBox1.Text = "" Or ComboBox3.Text = "" Or TextBox9.Text = "" Or TextBox1.Text = "" Or TextBox2.Text = "" _
        Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox7.Text = "" Then
            MsgBox("Complete The Schedule", MsgBoxStyle.Information)
        Else
            Dim lv As ListViewItem = ListView1.Items.Add(ComboBox7.Text)
            lv.SubItems.Add(ComboBox2.Text)
            lv.SubItems.Add(ComboBox4.Text)
            lv.SubItems.Add(ComboBox5.Text)
            lv.SubItems.Add(ComboBox6.Text)
            lv.SubItems.Add(TextBox2.Text)
        End If
    ElseIf ComboBox1.Text = "Second Year" Then
        If ComboBox1.Text = "" Or ComboBox3.Text = "" Or TextBox9.Text = "" Or TextBox1.Text = "" Or TextBox2.Text = "" _
        Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox8.Text = "" Then
            MsgBox("Complete The Schedule", MsgBoxStyle.Information)
        Else
            Dim lv As ListViewItem = ListView1.Items.Add(ComboBox8.Text)
            lv.SubItems.Add(ComboBox2.Text)
            lv.SubItems.Add(ComboBox4.Text)
            lv.SubItems.Add(ComboBox5.Text)
            lv.SubItems.Add(ComboBox6.Text)
            lv.SubItems.Add(TextBox2.Text)
        End If
    ElseIf ComboBox1.Text = "Third Year" Then
        If ComboBox1.Text = "" Or ComboBox3.Text = "" Or TextBox9.Text = "" Or TextBox1.Text = "" Or TextBox2.Text = "" _
        Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox9.Text = "" Then
            MsgBox("Complete The Schedule", MsgBoxStyle.Information)
        Else
            Dim lv As ListViewItem = ListView1.Items.Add(ComboBox9.Text)
            lv.SubItems.Add(ComboBox2.Text)
            lv.SubItems.Add(ComboBox4.Text)
            lv.SubItems.Add(ComboBox5.Text)
            lv.SubItems.Add(ComboBox6.Text)
            lv.SubItems.Add(TextBox2.Text)
        End If
    ElseIf ComboBox1.Text = "Fourth Year" Then
        If ComboBox1.Text = "" Or ComboBox3.Text = "" Or TextBox9.Text = "" Or TextBox1.Text = "" Or TextBox2.Text = "" _
        Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox27.Text = "" Then
            MsgBox("Complete The Schedule", MsgBoxStyle.Information)
        Else
            Dim lv As ListViewItem = ListView1.Items.Add(ComboBox27.Text)
            lv.SubItems.Add(ComboBox2.Text)
            lv.SubItems.Add(ComboBox4.Text)
            lv.SubItems.Add(ComboBox5.Text)
            lv.SubItems.Add(ComboBox6.Text)
            lv.SubItems.Add(TextBox2.Text)
        End If
    End If
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    If ListView1.SelectedItems.Count > 0 AndAlso MessageBox.Show("Do you want to remove this item?", "Confirm", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
        ListView1.SelectedItems(0).Remove()
    Else
        MsgBox("No item is selected", MsgBoxStyle.Information, "Message")
    End If
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.Text = "First Year" Then
        ComboBox7.Visible = True
        ComboBox8.Visible = False
        ComboBox9.Visible = False
        ComboBox27.Visible = False
    ElseIf ComboBox1.Text = "Second Year" Then
        ComboBox7.Visible = False
        ComboBox8.Visible = True
        ComboBox9.Visible = False
        ComboBox27.Visible = False
    ElseIf ComboBox1.Text = "Third Year" Then
        ComboBox7.Visible = False
        ComboBox8.Visible = False
        ComboBox9.Visible = True
        ComboBox27.Visible = False
    ElseIf ComboBox1.Text = "Fourth Year" Then
        ComboBox7.Visible = False
        ComboBox8.Visible = False
        ComboBox9.Visible = False
        ComboBox27.Visible = True
    End If
End Sub

conflict in database? Explain in detail about your problem.

for example when section 1 is already in the database for first year level it should prompt a message conflict because it is already save in the database

I am assuming we are talking about the event in Button5:

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
    If ComboBox1.Text = "First Year" Then
        If ComboBox1.Text = "" Or ComboBox3.Text = "" Or TextBox9.Text = "" Or TextBox1.Text = "" Or TextBox2.Text = "" _
        Or ComboBox4.Text = "" Or ComboBox5.Text = "" Or ComboBox6.Text = "" Or ComboBox7.Text = "" Then
            MsgBox("Complete The Schedule", MsgBoxStyle.Information)
        Else
            Dim lv As ListViewItem = ListView1.Items.Add(ComboBox7.Text)
            lv.SubItems.Add(ComboBox2.Text)
            lv.SubItems.Add(ComboBox4.Text)
            lv.SubItems.Add(ComboBox5.Text)
            lv.SubItems.Add(ComboBox6.Text)
            lv.SubItems.Add(TextBox2.Text)
        End If

If you can only have 7 periods, why not set an array to hold your periods. If the array contains a value for the period you are interested in then you can message the user that a conflict is occuring. If it's empty then you know it's a new entry.
If you make it a 2 dimensional array you can have all years all periods in the same array and save yourself all this checking.

PS: Try to name your objects a descriptive name.

how do i set an array? i'm sorry because i'm just a begginer in vb that's why it's hard for me to understand everything...

Untitled60 thank you for that but can you help me with this problem i'm encountering???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.