Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO!!

Status
Not open for further replies.

metgut

Technical User
Mar 2, 2002
7
US
How do you access a specific field using the following format?

Adodc1.RecordSet.Addnew

Is there a way such as:

Adodc1.Recordset("field") = something

I understand how its done when you hard code the ado object
Set Recordset = New ADODB.Recordset
....
....

Recordset("field") = something

I'm using data bound controls and the adodc object... but I want, I guess to bound a variable to the adodc object...

Something like:

Adodc1.Recordset("field") = something
Adodc1.Recordset.Addnew

so that the variable something gets written to the database along with the data bound controls

does any this make sense.

thanks

 
I think it's the following

Adodc1.Recordset.Fields("TheField")= something
Adodc1.Recordset.Addnew
 
You're not going to bind a variable such an integer or string to a recordset field in the sense that you can with controls like text boxes.

You can, however, assign the value of a specific field in a specific record the value that's stored in a common variable, depending, of course on the type of recordset you have.


There are 3 ways to reference the value contained in an rs field:

1. rs!fieldname 'this is the most efficient but least flexible since "fieldname" cannot be a variable. It must be a hardcoded field name.

This is how an assignment using the previous notation would look
dim str as string
rs!Name = str

2. rs.Fields(2).value 'you can use the recordsets fields collection. This is flexible, since the value in the parens can be an integer variable, but it's not entirely useful because it requires that you know which field is in which position in the collection. Assignment:
dim str as string
rs.Fields(2).value = str

3. rs.fields("Fieldname").value 'this is the most flexible and most useful because the value in the parens can actually be string variable which stores field names. It's not surprising though, that this method creates the most runtime overhead and takes the longest time to execute.

Whenever possible I use the first access method.

Hope this helps!
Josh

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top