this thing is getting into my nerves and i really don't know what to do.. i tried a lot of variations in my code and even sql statement but still nothing happens.. i really need to do thing messed up project of mine and put all my efforts here.. but i really can't understand why my combo box isn't showing the names of the candidates w/ that designated position.. please help me, heres my current code:

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()


        If cbPartylist.Text = (dr("PartylistName").ToString()) Then
            dr = cmd.ExecuteReader
            While dr.Read()
                cbPres.Text = (dr("Lname") & ", " & dr("Fname") & " " & dr("MI").ToString())
            End While
        End If
        cn.Close()

---
i am working on a university student council voting system and what i wanted to do is when the voter selected the radio button name "Vote by Party list" automatically the names of all the partylist that are entered in the databse will be listed in the combo box and all the candidates on that Party list will be shown on the individual combo boxes made for each position..

Plase, be so kind to try

dr = cmd.ExecuteReader
While dr.Read()
    If cbPartylist.Text = (dr("PartylistName").ToString())Then
        cbPres.Items.Add dr("Lname") & ", " & dr("Fname") & " " & dr("MI").ToString())
    End If
End While

Hope this helps

commented: Solved +8

thank you for your response,..
but still nothing shows.. i really don't know how will i retrieved my data,,, :(

The dr has rows?

i also used that code before ending up to my last posted one.. but still nothing happens..

yes... im pertaining to my rows in my access that will be converted to string

Please try

dr = cmd.ExecuteReader
if dr.HasRows() then
    While dr.Read()
        If cbPartylist.Text = (dr("PartylistName").ToString())Then
            cbPres.Items.Add (dr("Lname") & ", " & dr("Fname") & " " & dr("MI").ToString())
        End If
    End While
Else
    MsgBox "Nothing to show"
End If

And let us know the result.

Hope this helps

hmm.. nothing.. happens. o.O
uhmm what do you think maybe my problem on my syntax?

I found that in the returned data there is no PartylistName field. You only return the fields Lname, Fname and MI according to your select clause.

Sorry not to see it before.

dr = cmd.ExecuteReader
if dr.HasRows() then
    While dr.Read()
            cbPres.Items.Add (dr("Lname") & ", " & dr("Fname") & " " & dr("MI").ToString())
    End While
Else
    MsgBox "Nothing to show"
End If

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.