Help me out here! plz

Results 1 to 2 of 2

Thread: Help me out here! plz

  1. #1
    Eric Morillo Guest

    Default Help me out here! plz

    Hi iam new to stored procedures... <BR><BR>I would like to insert alot of values in to a database and then return the ID och the just inserted record... I have read som FAQ´s and come up with the following soultion. AND IT WORKS... <BR><BR>But the problem is that in this code/exampel i have to code lots of statments if i would like to insert all those values i would like to post. IS there a way to save redundent code here ? <BR><BR>&#039;************************************ ******&#039; <BR>&#039;*** Declare variables ***&#039; <BR>&#039;**************************************** **&#039; <BR><BR>dim dataConn, adocmd, IsValid <BR><BR>test = "This is a test" <BR><BR>set dataConn = Server.CreateObject("ADODB.Connection") <BR>dataConn.Open "DSN=test" &#039;make connection <BR><BR><BR>&#039;******************************** **********&#039; <BR>&#039;*** EXECUTITON ***&#039; <BR>&#039;**************************************** **&#039; <BR><BR>Set adocmd = Server.CreateObject("ADODB.Command") <BR>adocmd.CommandText = "sp_test" <BR>adocmd.ActiveConnection = dataConn <BR>adocmd.CommandType = adCmdStoredProc <BR><BR>adocmd.Parameters.Append adocmd.CreateParameter("ID", adInteger, adParamReturnValue, 4) <BR><BR>&#039; THIS IS WHAT I MEAN, DO i HAVE TO REPEAT THIS LINE FOR EVERY SINGEL VALUE I WOULD LIKE TO INSERT? <BR><BR>&#039; say that i want to post the variable test1 to 20 <BR>adocmd.Parameters.Append adocmd.CreateParameter("test", <BR>adVarChar, adParamInput, 50, test) <BR><BR><BR>adocmd.Execute <BR><BR>testID = adocmd.Parameters("ID").Value <BR>test = adocmd.Parameters("test").Value <BR><BR>Response.write testID <BR>Response.write test <BR><BR><BR>Hope you understand my question =D <BR><BR>TNX

  2. #2
    SPG Guest

    Default The answer is...

    ... no. Great news.<BR><BR>objConn.execute "sp_foo &#039;" & param1 & "&#039;, &#039;" & param2 & "&#039;, &#039;" & param3 & "&#039;"<BR><BR>is valid syntax when passing scalar (string-able) values to the database. The thing to watch out for is the numbers like 100,000.00 because they don&#039;t go in &#039;s (so the , in 100,000 confuses the database into thinking that there are 2 parameters, not just 1 -- so just replace("100,000.00", ",", "") and your problem is solved for those numbers).<BR><BR>HiH -- and makes your source code short & pretty.<BR>JM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts