Click to See Complete Forum and Search --> : FormView


tavo2k1
10-05-2006, 08:33 PM
I created a formview to create new users using the insert command. It works fine but how do a retrive a Parameter that I pass back when rendering back at the user? the parameter contains the value for "@@Identity" for the record I just created.

jvanamali
10-06-2006, 01:28 PM
you can use a select statement that retrieves maximum id from your users table, to be extra sure you can use username,password etc fields that u have to insert into users table (any way if username is unique you will get only one record , no need of max(userid), pwd,email in where condtn)

For Example

Insert into Users (Username,pwd,email) values ("abc","abc","abc@abc.com")
Select max(userid) from users where username = uname and pwd = password and email = email

tavo2k1
10-06-2006, 06:59 PM
Thanks but the problem resides in geting back the parameter back to the FormView.

I need to get Parameter back with the ID of new record I created. Geting the ID in a SQL statem is easy, I tested the query in the SQL Query Analizer and it works fine. But how do I get the parameter back to the calling page.

I am using a 3 Tier layer, I use a DataSet Schema fiile to interface to my data base. It should return a parameter back with the ID of new record inserted. Here is the query I use to insert new record;

INSERT INTO Contacts (FirstName, LastName) Values('Garbage', 'Test');
SELECT SCOPE_IDENTITY()

Please help, or send me links to sites where I can get resources, thank you.

Gus G.

jvanamali
10-07-2006, 08:08 AM
if you not using a stored procedure

Set Rs = Server.CreateObject("ADODB.Recordset")
SQL = "INSERT INTO Contacts (FirstName, LastName) Values('Garbage', 'Test')"
Conn.Execute Sql,rowsAffected
If rowsAffected > 0 Then
Sql = "SELECT SCOPE_IDENTITY"
Rs.Open Sql,Conn ,1
Set GetMaxCartID = Rs(0)
Endif

for retrieving data from stored procedure using asp 3.0
http://www.aspfree.com/c/a/Database-Code/Using-Stored-Procedures-to-write-records-and-retrieve-ALL-DATA/

http://www.computerbooksonline.com/chapters/asp3ch3.htm