CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: COMBO and ADO

  1. #1
    Guest

    COMBO and ADO

    I am using ADO. I have 1 combo box and 7 textboxes on my form. On the basis of selecting any item
    in combo box i want to fill all the 7 text boxes with the data related to the item selected in combo box.
    I am getting the list of items in combobox from the SQL Server data.
    if anybody can help providing sample code....
    thanks in advance
    sanjay


  2. #2
    Join Date
    Jan 2000
    Posts
    16

    Re: COMBO and ADO

    Try something like this.


    on error GoTo Errors

    set db = new Connection
    db.CursorLocation = adUseClient
    db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=E:\training\WinPrism ODBC Database\WinPrismData.mdb;"

    set adoPrimaryRS = new Recordset
    adoPrimaryRS.Open "select StoreID,ODBCDriver,UserID,Password,IPAddress,Server from StoreLocations", db, adOpenStatic, adLockOptimistic


    Dim sql as string 'Declare a string to hold the SQL statement

    cboBox.Clear
    'Clear the combobox in question, in case it isn't
    sql = ""
    'Clear SQL in case there is another var named SQL somewhere
    'Setup SQL to select fields based on the values passed to the function
    sql = "SELECT " & IDField & descField & " FROM " & strTB

    With adoPrimaryRS

    Do Until .EOF 'Loop until the End of the recordset

    'Add the items to the combo box
    cboBox.AddItem adoPrimaryRS(descField)
    cboBox.ItemData(cboBox.NewIndex) = adoPrimaryRS(IDField)
    .MoveNext

    Loop
    .MoveFirst
    .Close


    End With

    'set adoPrimaryRS = nothing 'Release the variable
    cboBox.ListIndex = 0

    Exit Sub

    Errors: 'error handler

    If Err.Number <> 0 then

    MsgBox ("error #: " & Str(Err.Number) & Err.Description)
    Exit Sub

    End If







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured