1. com.commandtext = sql_query
Set Rs = com.execute
2. Rs.Open sql_query, myConnection
Is there any difference?
> 1. com.commandtext = sql_query
> Set Rs = com.execute
>
> 2. Rs.Open sql_query, myConnection
>
> Is there any difference?
Do you hammer nails with a spanner? No.
Read data into a [configured] recordset object, execute [raw]
commands through a connection object. You get a lot more control
over the recordset if you have a recordset object to play with in the
first place - without it, you have to put up with the defaults, which are
often /not/ want you need.
HTH,
Phill W.
Graham Dobson - 31 Jul 2003 16:23 GMT
> commands through a connection object. You get a lot more control
> over the recordset if you have a recordset object to play with in the
> first place - without it, you have to put up with the defaults, which are
> often /not/ want you need.
Agreed, but if you just need to read a value or something similarly limited
(or control your update/insert functionality) encapsulating your data
manipulation through methods which use parameterised command objects can be
a good design approach. -- Graham
It depends what you're trying to do
Option 1 makes the recordset read-only and you can only go forward
through the recordset. You cant do .RecordCount on it. However, its
better for parametereized (did I spell that right??!!) queries I
believe
Option 2 allows you to have other recordset options and is ideal for
opening simple queries.
If however, you are doing updates, deletes or inserts where you're not
returning a recordset, then just use the ADODB.Command object
com.commandtext = sql_insert_update_or_delete
com.execute
No point retrieving a recordset if you're not going to use it.
> 1. com.commandtext = sql_query
> Set Rs = com.execute
>
> 2. Rs.Open sql_query, myConnection
>
> Is there any difference?