PDA

Click to See Complete Forum and Search --> : ADO controls: how to bind data to the textbox


sultan
Jun 4th, 2000, 08:14 PM
Hi all
I want to know if I can achieve the followings when using an ADO control on the form:

Dim dbSe As Connection
Dim recSet2 As Recordset

Set dbSe = New Connection
dbSe.Provider = "msdasql"
dbSe.ConnectionString = "dsn=Xtreme sample" _
& "data;uid=sa;pwd=;"

dbSe.Open

Set recSet2 = New Recordset
recSet2.Open "select * from customer", dbSe, _
& adOpenDynamic, adLockPessimistic

txtFields.DataField = "Customer ID"
Set txtFields.DataSource = adoPrimaryRS

I got a ADO control on the form called 'adoRecset' which refers to a DSN and then for its recordset to a table call 'customer'.

compuGEEK
Jun 4th, 2000, 10:32 PM
Try setting the textbox this way:


txtFields.text = adoRecset.customerID

sultan
Jun 4th, 2000, 10:53 PM
No the porblem is that it complains that the object is not set and i am having problem 'opening' the 'adorecset' remember its an ado control on the form.

how do i
open it without binding any object directly becasue as soon as you bind any object ie bind a text box to the data control then it is opened,referenced and instantiated. but how do i get it to work just using source code.

sultan
Jun 5th, 2000, 09:53 PM
ANY REPLY APPRECIATED!

Clunietp
Jun 6th, 2000, 12:11 PM
so you want to bind a textbox to a recordset object, and NOT a data control?

sultan
Jun 6th, 2000, 03:37 PM
actually Clunietp I want to bind it to data control binding it to a recordset object is already done see my code above.

Maybe if we forget the textbox and just say once you have assigned a DSN and a table to your ADO control then :
How do i using source code open the ado data control connection so its recordset is set and ready to be used?

Clunietp
Jun 6th, 2000, 10:04 PM
Originally posted by sultan

How do i using source code open the ado data control connection so its recordset is set and ready to be used?



huh? the recordset is set and ready to be used when your form loads and the data control populates itself....

I must be missing your ultimate goal here....

sultan
Jun 6th, 2000, 10:24 PM
Thanks Clunietp

1) Drag one ADO data control onto form.

2) Drag one textbox onto form.

3) Set the ADO control's ADODC property and choose an appropriate DSN for its ODBC data source name then choose a table for its record source.

4) Leave all the properties of the text box default at design time.

Now using source code bind the text box to the ado data control.

ie
txtbox1.DataField = "Customer ID"
Set txtbox1.DataSource = adoDataControl

Clunietp
Jun 7th, 2000, 09:14 AM
OK

I put this into form_load:


Private Sub Form_Load()

Text1.DataField = "CustomerID"
Set Text1.DataSource = Me.Adodc1

End Sub


It works fine, the textbox is bound to the data control

I set the connection string of the data control and put in a recordsource

sultan
Jun 7th, 2000, 10:02 PM
Many thanks Clunietp
The silly thing works for me as well but I can almost swear the same combination of code failed everytime I tried it in the past!!

WHAT IF I don't want to use any of the controls including the text box how can you access the record set that i want using the ADO Control.