|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
NewBie Question: SQL Server AddNew and ASPI'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 > 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> 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. 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 Yes! This is exactly how you add a new row to a table, and your resolution > using an Insert statement. 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 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 |
|||||||||||||||||||||||