binding dbcombo to an ADO

starstarstarstarstarstarstarstarstarstar Rating: 0/5 (0 vote cast) print

hello friends,

I want to bind my DBcombo to and ADO recordset at run time. how is that possible? can you help me in that ?
I want to create every thing in my code at run time.

thanks for your help.
roseta.

 : roseta     Reply  

Replies (1)

Is this VB 6 or VB .Net?In VB 6, the dbcombo control exposes a RowSource property for the datasource that will populate the combo box items, and a DataSource property that will populate/accept the selected item. The code below illustrates:

' Recordset used to populate the combo box items for selectionDim rowsourceRS as new ADODB.Recordset' Recordset that contains the data field to be populatedDim datasourceRS as new ADODB.Recordset' Populate the recordsetsrowsourceRS.Open "Select id, name from ref_types", myConnectiondatasourceRS.Open "Select recid, mnyame, mytype from recs ", myConnection, adOpenDynamic' Set the required fields for the dbcombodbCombo.RowSource = rowsourceRSdbCombo.Listfield = "name" ' Field for the listdbCombo.BoundColumn = "id"' Value field to pass backdbCombo.DataSource = datasourceRSdbCombo.DataField = "mytype" ' Field in the datasource to updateFrom here, the databinding should take care of updating your recordset.Hope this helps.



Post A Reply

 Questions & Answers