Retrieving data from ms access DB to combobox

IT_Student_604

New member
Joined
Sep 24, 2011
Messages
1
Location
philippines
Programming Experience
1-3
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:


  1. Private Sub cbPres_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbPres.SelectedIndexChanged
  2. constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = " & Application.StartupPath & _
  3. "\SSC_Automation.mdb; Persist Security Info = False"
  4. cn.ConnectionString = constr
  5. cmd = New OleDbCommand("select Lname,Fname,MI from tblCandidates where CandPosition='President'" _
  6. & "and PartylistName='" & cbPartylist.Text, cn)
  7. cn.Open()
  8. dr = cmd.ExecuteReader
  9. While dr.Read()
  10. cbPres.Items.Add(dr("Lname") & dr("Fname") & dr("MI").ToString())
  11. End While
  12. cn.Close()
  13. 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

----------------------
really need ur help so badly guys.. please please.. >_<
thanks in advance
 
Here you go :)

VB.NET:
Dim cn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
                                                        & "Data Source=C:\Users\Home\Desktop\Database1.mdb;")
        cn.Open()
        Dim str As String = "SELECT * FROM tblCandidates WHERE CandPosition='President' " _
        & "and PartylistName='" & TextBox1.Text & "'"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim dr As OleDbDataReader = cmd.ExecuteReader

        While dr.Read
            ComboBox1.Items.Add(dr("LName") & ", " & dr("FName") & ", " & dr("MI"))
        End While
        cn.Close()
 
Back
Top