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..

Edited 5 Years Ago by IT_Student_604: n/a

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

Comments
Solved

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

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

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

Edited 5 Years Ago by lolafuertes: n/a

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

This article has been dead for over six months. Start a new discussion instead.