Home All Groups Group Topic Archive Search About

NewBie Question: SQL Server AddNew and ASP

Author
29 Dec 2005 5:12 PM
mac
I'm new to VBscript and SQL Server.  I want to add a row to a SQL Server
table.  I establish the database connection.  I set up an recordset.  I then
Open the recordset.  At this point I get an error.  Is this because I must
code an select statement first. 

What I'm trying to do is add a new record to the table.  I have resolved
using an Insert statement.

Want to know for future refernce.
--
mac0730

Author
29 Dec 2005 5:24 PM
Aaron Bertrand [SQL Server MVP]
> I'm new to VBscript and SQL Server.  I want to add a row to a SQL Server
> table.  I establish the database connection.  I set up an recordset.  I
> then
> Open the recordset.  At this point I get an error.  Is this because I must
> code an select statement first.

Why do you need to SELECT data to insert a row?  This is like

Simplify, man.  Create a stored procedure that says:

CREATE PROCEDURE dbo.AddRow
    @value INT
AS
BEGIN
    SET NOCOUNT ON;
    INSERT dbo.YourTable(Values) SELECT(@Value);
END
GO

Now, from VBScript, just conn.execute("EXEC dbo.AddRow @value = 5")

(Or use the ADODB.Command object.)

http://www.aspfaq.com/2201
http://www.aspfaq.com/params.htm

> What I'm trying to do is add a new record to the table.  I have resolved
> using an Insert statement.

Yes!  This is exactly how you add a new row to a table, and your resolution
is moving you in the right direction.  (I don't know where it comes from,
this common misperception that you need a recordset to add/update/delete
data... recordsets are for RETRIEVING one or more rows of data.)  Next, use
a stored procedure... you should strive to never have ad hoc SQL embedded in
application code... it belongs in the data tier.

A
Author
29 Dec 2005 6:24 PM
JT
If you are not returning a recordset, then just specify the name of the
table. For example:

Rs.open("mytable")

Show quote
"mac" <m**@discussions.microsoft.com> wrote in message
news:07DEECF8-412E-40AD-926D-EC8822790045@microsoft.com...
> I'm new to VBscript and SQL Server.  I want to add a row to a SQL Server
> table.  I establish the database connection.  I set up an recordset.  I
> then
> Open the recordset.  At this point I get an error.  Is this because I must
> code an select statement first.
>
> What I'm trying to do is add a new record to the table.  I have resolved
> using an Insert statement.
>
> Want to know for future refernce.
> --
> mac0730

AddThis Social Bookmark Button