NewBie Question: SQL Server AddNew and ASP

NewBie Question: SQL Server AddNew and ASP

Post by bWFj » Sat, 31 Dec 2005 02:12:02


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
 
 
 

NewBie Question: SQL Server AddNew and ASP

Post by Aaron Bert » Sat, 31 Dec 2005 02:24:54

> I'm new to VBscript and SQL Server. I want to add a row to a SQL Server

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.yqcomputer.com/
http://www.yqcomputer.com/


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

 
 
 

NewBie Question: SQL Server AddNew and ASP

Post by JT » Sat, 31 Dec 2005 03:24:18

If you are not returning a recordset, then just specify the name of the
table. For example:

Rs.open("mytable")