-- hello there!, here i am again asking for some help... i want to retrieve my data from my ms access database and i it gave me this error..

"Index was outside the bounds of the array."
------
can someone help me about this?.. i put my code on my radio button function because, what i wanted to happen is when the user selected the "vote by party list" selection the party list names will automatically load on the activated combo box.

here's my code..

Private Sub rbPartylist_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbPartylist.CheckedChanged
        If rbPartylist.Checked = True Then
            cbPartylist.Enabled = True

            constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Application.StartupPath & _
                  "\SSC_Automation.mdb; Persist Security Info = False"
            cn.ConnectionString = constr

            cmd = New OleDbCommand("select CandPosition from tblCandidates", cn)
            cn.Open()

            dr = cmd.ExecuteReader

            While dr.Read()
                cbPartylist.Items.Add(dr(9).ToString())
            End While
        End If
    End Sub
Member Avatar for Unhnd_Exception

maybe you meant to type in dr(0) instead of 9. I would change it to dr("CandPosition")

ok let me try it.. thank you.. :)

the code works thanks but i have this another problem ..

i want my other combo boxes to generate the names of the candidates that are members of the party list the voter had selected in my partylist combo box.. i've tried playing on my codes but still nothing was retrieved by my combo boxes.

here's my code:

Private Sub cbPres_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbPres.SelectedIndexChanged

            constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Application.StartupPath & _
                   "\SSC_Automation.mdb; Persist Security Info = False"
            cn.ConnectionString = constr

        cmd = New OleDbCommand("select Lname,Fname,MI from tblCandidates where CandPosition='President'" _
                               & "and PartylistName='" & cbPartylist.Text, cn)
            cn.Open()

            dr = cmd.ExecuteReader

            While dr.Read()
            cbPres.Items.Add(dr("Lname") & dr("Fname") & dr("MI").ToString())
                
            End While
            cn.Close()

    End Sub

---
i'm trying to retrieved the name of the candidate pertaining on the position they're running and the party list selected using the partylist combo box

badly needed your help guys.. i'm still getting confused about vb.net and sql..

Member Avatar for Unhnd_Exception

maybe you meant to add a ' at the end of your query string.

PartylistName='" & cbPartylist.Text, cn) & "'"

And you need a space before " and

Also Read up on SqlParameters.

uhm do you mean like this one?

" and PartylistName='" & cbPartylist.Text, cn) & "'"
--
but that will make an error..

what i made last night was like this..

cmd = New OleDbCommand("select Lname,Fname,MI from tblCandidates where CandPosition='President'" _
& "and PartylistName='" & cbPartylist.Text & "'", cn)

but still nothing happens...

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.