|
 |
asp_databases thread: Newbie INSERT and AddNew question
Message #1 by "Jennifer Carter" <jen1503@h...> on Sun, 17 Jun 2001 20:49:49
|
|
Hello,
I'm very new to all this so I hope you will bear with me. Can anyone just
confirm if my understanding is correct:
1. Do you use the MoveLast, AddNew and Update methods when inserting a
new record via a recordset and you use the INSERT statement for non-
recordsets?
2. Do you have to use the MoveLast and AddNew methods before using the
INSERT statement or does INSERT know to add a new record automatically?
3. Does INSERT always add a *new* record?
I know these questions are kinda dumb but for a beginner they can be quite
confusing. Hope you'll help!
Regards,
Jen
Message #2 by "Ken Schaefer" <ken@a...> on Mon, 18 Jun 2001 15:32:28 +1000
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: I'm very new to all this so I hope you will bear with me.
: Can anyone just confirm if my understanding is correct:
:
: 1. Do you use the MoveLast, AddNew and Update methods
: when inserting a new record via a recordset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You don't need .movelast.
Just use .addNew and .Update
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: and you use the INSERT statement for non-recordsets?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A recordset is something that is related to ADO (ActiveX Data Objects) - it
it basically where you get something from the database, and you're keeping a
copy of the data (or at the very least, the structure of the data), outside
the database. If you make changes to the data in the recordset, you then
need to flush these back to the database (eg by calling .Update)
SQL statements are just text strings to ASP - they only mean something to a
database. A SELECT query will return a results set, which you can then put
into a recordset. An INSERT statement never returns any results, so it
doesn't have anything to do with Recordsets...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: 2. Do you have to use the MoveLast and AddNew methods
: before using the INSERT statement or does INSERT
: know to add a new record automatically?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INSERT isn't something that is handled by ADO/ASP - an INSERT SQL statement
is just a text string that doesn't mean anything in particular, *except* to
a database. If you pass this particular text string to a database, it parses
it, and inserts a new record. eg
<%
strSQL = _
"INSERT INTO table1 (field1, field2) " & _
"VALUES ('va1', 'test2')"
objConn.execute strSQL,,adCmdText+adExecuteNoRecords
%>
All you do above is send the text string down the connection to the
database, and the database processes it. An INSERT statement will always try
to insert a new record into the table in question.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: 3. Does INSERT always add a *new* record?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yes (provided the syntax is OK, and you aren't breaking any rules that
you've defined in the database etc).
Here's a good beginners guide to SQL:
http://w3.one.net/~jhoffman/sqltut.htm
Cheers
Ken
Message #3 by "Jennifer Carter" <jen1503@h...> on Mon, 18 Jun 2001 11:10:48
|
|
Thanks for taking the time to write such a thorough answer Ken. Thanks
too for your answer in beginning_asp which was equally helpful!
Regards,
Jen
|
|
 |