hello ! can you please help me..?

i want to limit the number of students(60) that will be enrolled in one section and prompt a message that it surpass the limit.... i inserted it in my combobox1
..here's my code :

strsql = "select  * from Schedulings where Sections = '" & ComboBox1.Text & "'"
    Dim acscmd As New OleDb.OleDbCommand

    acscmd.CommandText = strsql
    acscmd.Connection = asconn
    acsdr = acscmd.ExecuteReader()
    TextBox9.Clear()
    TextBox5.Clear()
    ListView1.Items.Clear()
    If acsdr.Read = 2 Then
        MsgBox("Too many enrolled in this section")
    Else

        While (acsdr.Read())
            TextBox9.Text = (acsdr("SectionNames"))
            TextBox5.Text = (acsdr("Adviser"))
            showmyrecords()
        End While
        acscmd.Dispose()
        acsdr.Close()
    End If

it doesnt work. how should i do it?

kindly help me

Recommended Answers

All 8 Replies

What is it ComboBox1.Text written?

So you want to do inseetion on each enrollment? And when this number goes over 60 pop up a message?

the combobox1 contains the sections .. i want to limit student to be enrolled in that particular section to 60 students snd prompt the user that it surpass the limit of the number of student on that section.. the prompt must be show when the user choose the section on combobox1.

u can use the count function in the select query, if the count returns more than sixty values then prompt the message...

 Dim temp as Integer
 Try
    Dim myReader As OleDbDataReader
    Dim sql As String = "SELECT count(*) as total from tablename where Section='" + combobox1.Text + "'"
    Dim comm As OleDbCommand = New OleDbCommand(sql, Connection)
    Debug.Print("Query: " + comm.CommandText)
    myReader = comm.ExecuteReader
    While myReader.Read()
        temp = myReader.Item("total")
    End While
    If temp > 60 Then
        MsgBox("Exceeding limit")
    End If
    myReader.Close()
Catch ex As Exception
    MsgBox(ex.Message)
End Try

Did this help u???

i'm so sorry for late reply .. i already insert it in my codes.. but it doesnt limits.. or am i insert it on the wrong part..? please help me? :)

Dim temp As Integer


    strsql = "select  * from Schedulings where Sections = '" & ComboBox1.Text & "'"
    Dim acscmd As New OleDb.OleDbCommand

    acscmd.CommandText = strsql
    acscmd.Connection = asconn
    acsdr = acscmd.ExecuteReader()
    TextBox9.Clear()
    TextBox5.Clear()
    ListView1.Items.Clear()

    Try
        Dim myReader As OleDbDataReader
        Dim sql As String = "SELECT count(*) as total from Enlistment where Sections='" + ComboBox1.Text + "'"
        Dim comm As OleDbCommand = New OleDbCommand(sql, asconn)
        Debug.Print("Query: " + comm.CommandText)
        myReader = comm.ExecuteReader
        While myReader.Read()
            temp = myReader.Item("total")
        End While
        If temp > 2 Then
            MsgBox("Exceeding limit")
        End If
        myReader.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

    While (acsdr.Read())
        TextBox9.Text = (acsdr("SectionNames"))
        TextBox5.Text = (acsdr("Adviser"))
        showmyrecords()
    End While
    acscmd.Dispose()
    acsdr.Close()


End Sub

What issue are u facing now??? does ur Sections column in database contain any value??? in which procedure are u writting this code???

are you getting anything in myreader? myreader.hasrows=true?

yes SEction column have value.. i wrote that code in my combobox1 which contains the sections..

it does not count the value in the Sections columns that's why whenever i choose the section that already contains 2 same sections it can be enlisted all over again.

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.