how to get data from database using combobox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rekhasc
    New Member
    • Oct 2007
    • 66

    how to get data from database using combobox

    hi.........
    can anyone help me to write the code to get a field from database using combobox and that should display the corresponding record in Msflexgrid using vb6.0
    I am using access 2007 and adodb
  • VEnkatramasamy
    New Member
    • Oct 2007
    • 6

    #2
    HI,

    I hope you know Adodb connection and record set usage
    use an while loop to add itemsto the combo box upto end of record Reached

    Example
    RS-Record set
    Cbo1-Combobox

    Code
    rs.move first
    While not rs.eof
    cbo1.additem=rs .fields(0) 'corresponding field Index

    rs.move next
    wend


    you can use below code too
    cbo1.additem=rs !FiledName

    Have a nice day

    With regards

    Venkatramasamy SN

    Comment

    • debasisdas
      Recognized Expert Expert
      • Dec 2006
      • 8119

      #3
      try this sample code

      [code=vb]
      Set CboName.DataSou rce = Rs
      For i = 0 To Rs.RecordCount - 1
      CboName.AddItem Rs(0)
      Rs.MoveNext
      Next i
      Rs.Close
      [/code]

      Comment

      • rekhasc
        New Member
        • Oct 2007
        • 66

        #4
        Originally posted by VEnkatramasamy
        HI,

        I hope you know Adodb connection and record set usage
        use an while loop to add itemsto the combo box upto end of record Reached

        Example
        RS-Record set
        Cbo1-Combobox

        Code
        rs.move first
        While not rs.eof
        cbo1.additem=rs .fields(0) 'corresponding field Index

        rs.move next
        wend


        you can use below code too
        cbo1.additem=rs !FiledName

        Have a nice day

        With regards

        Venkatramasamy SN


        its giving an compile error argument not optional

        Comment

        • rekhasc
          New Member
          • Oct 2007
          • 66

          #5
          Originally posted by rekhasc
          its giving an compile error argument not optional

          thanx a lot............ ............

          Comment

          • debasisdas
            Recognized Expert Expert
            • Dec 2006
            • 8119

            #6
            You need to pass the value from the combobox to the where clause of the SQL query and pas the result to the flexgrid.

            Comment

            Working...