i'm working on an e-voting system for my thesis... but i'm having problem on how to output the data in all the rows in the database in a check box. so it means that the number of checkbox is equals to the row of the table. i manage to output only one data from the first row but i don't know how can i output all the succeeding rows. hope you could help me.

this is my code so far

Private Sub LoadCandidates()
        SqlString = "SELECT * FROM candidate"
        'Function for searching by candidate ID number
        Using conn As New MySqlConnection(ConnString)

            Using cmd As New MySqlCommand(SqlString, conn)

                cmd.CommandType = CommandType.Text

                conn.Open()

                Using reader As MySqlDataReader = cmd.ExecuteReader()

                    If reader.HasRows = True Then
                        While reader.Read()

                            CheckBox1.Text = reader("candidateLname").ToString
                            
                        End While

                    End If

                End Using

            End Using

        End Using

    End Sub

Recommended Answers

All 3 Replies

You need to create a new checkbox for each row, and add the new check box to your forms or page at run time, not at design.

On line 17 you need to:
Dim Cb as new Checkox : cb.name = "Chk" & reader("CandidateId").ToString : cb.text = reader("candidateLname").ToString : Me.Controls.add(cb)


To recover the resulsts, you must cicle on the form or page controls to get the controls wich name beguns with "Chk" and then, the rest of control name will give you the candidate id, and the Checked property will give you the voting.

Maybe you will need to set the cb location in the form or page.

Hope this helps.

You need to create a new checkbox for each row, and add the new check box to your forms or page at run time, not at design.

On line 17 you need to:
Dim Cb as new Checkox : cb.name = "Chk" & reader("CandidateId").ToString : cb.text = reader("candidateLname").ToString : Me.Controls.add(cb)


To recover the resulsts, you must cicle on the form or page controls to get the controls wich name beguns with "Chk" and then, the rest of control name will give you the candidate id, and the Checked property will give you the voting.

Maybe you will need to set the cb location in the form or page.

Hope this helps.

thanks for the reply lolafuertes... i tried your code... but it only outputs the first row... what i want is that everytime the reader encounter a row which is not null, it will make a checkbox with the Lastname of the candidate. if database row is 5 then it will also make 5 check boxes . i hope you could help me. thanks in advance

You will need to add
cb.top = topcornerpositionintheformorpage: cb.left = leftcornerpositionintheformorpage: cb.visible=true

inorder each new check box will appear in a disticnt place, being topcornerpositionintheformorpage an integer inticating the number of pixels since the top of the form for the new check box, and leftcornerpositionintheformorpage an integer inticating the number of pixels since the left edje of the form for the new check box, and assuring the visibility.

Hope this helps

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.