Wednesday, October 7, 2009

ADODB in javascript- Stored procedure

Here is an example of calling a stored procedure (this inside a classic ASP PAGE) using javascript as your code:

var cn = Server.CreateObject("ADODB.Connection");
var cmd = Server.CreateObject("ADODB.Command");
var para = Server.CreateObject("ADODB.Parameter");
var adCmdStoredProc = 4; //set adodb enumeration value
var adVarChar = 200 ;
var adParamInput = 1 ;
cn.open("DSN", "User", "Pass");
cmd.ActiveConnection = cn;
cmd.CommandText = "procedure";
cmd.CommandType = adCmdStoredProc;
cmd.Parameters.Append(cmd.CreateParameter("@Input", adVarChar, adParamInput, 250));

cmd.Parameters("@Input") = "Input this";
cmd.Execute();

One thing to watch for when passing in a varchar input string: Please make sure when you create the parameter, that you pass in the size of the parameter in the stored procedure as the last input of creation. I had a varchar250 field in this one.

No comments:

Post a Comment