954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HELP! detting data from ms acceass databse to combo box

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

IT_Student_604
Light Poster
34 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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

lolafuertes
Master Poster
798 posts since Oct 2008
Reputation Points: 120
Solved Threads: 167
 

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

IT_Student_604
Light Poster
34 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

The dr has rows?

lolafuertes
Master Poster
798 posts since Oct 2008
Reputation Points: 120
Solved Threads: 167
 

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

IT_Student_604
Light Poster
34 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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

IT_Student_604
Light Poster
34 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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

lolafuertes
Master Poster
798 posts since Oct 2008
Reputation Points: 120
Solved Threads: 167
 

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

IT_Student_604
Light Poster
34 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 

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

lolafuertes
Master Poster
798 posts since Oct 2008
Reputation Points: 120
Solved Threads: 167
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: