|
 |
activex_data_objects thread: Inserting a new record
Message #1 by "Pete Davis" <pdavis@q...> on Wed, 15 Aug 2001 15:24:07 -0400
|
|
I'm using ADO with MS SQL Server.
I want to insert a new record into a table, but I need to do it via a
recordset, not a SQL INSERT statement. What's the generally accepted
method of doing this? Do I need to do a select on the table to get a
connected recordset first, or can I create a disconnected recordset by
hand and then "attach" it to a table somehow?
Thanks.
Pete
Message #2 by "david adams" <davidadams00@h...> on Wed, 15 Aug 2001 20:09:43
|
|
if you create a disconnected recordset, you can then do an addnew and cycle
through the fields of your recordset before you call the update method.
assuming rs is your manually created disconnected recordset.
you can:
rsaddnew.open
rsaddnew.addnew
for each fld in rs.fields
rsaddnew.fields("fieldname").value = rs.fields("fieldname").value
next fld
rsaddnew.update
i think this would only gain you the performance advantage if you open the
recordset and perform the addnew before you finish setting your values for
the add. if you get your values and save them to a collection (like a
command object) before you do your open and addnew, i dont know if the
disconnected method gets you a noticeable performance upgrade.
youd do better using a stored procedure, but i am sure you already knew
that.
david adams
>
>I'm using ADO with MS SQL Server.
>
>I want to insert a new record into a table, but I need to do it via a
>recordset, not a SQL INSERT statement. What's the generally accepted method
>of doing this? Do I need to do a select on the table to get a connected
>recordset first, or can I create a disconnected recordset by hand and then
>"attach" it to a table somehow?
>
>Thanks.
>
>Pete
Message #3 by Thomas Bellavia <TBellavia@V...> on Thu, 16 Aug 2001 09:01:28 -0400
|
|
For simplicity just 'open()' a recordset 'SELECT'ing the table and do an
'addnew()' .
-----Original Message-----
From: Pete Davis [mailto:pdavis@q...]
Sent: Wednesday, August 15, 2001 3:24 PM
To: ActiveX_Data_Objects
Subject: [activex_data_objects] Inserting a new record
I'm using ADO with MS SQL Server.
I want to insert a new record into a table, but I need to do it via a
recordset, not a SQL INSERT statement. What's the generally accepted method
of doing this? Do I need to do a select on the table to get a connected
recordset first, or can I create a disconnected recordset by hand and then
"attach" it to a table somehow?
Thanks.
Pete
|
|
 |