About this user

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

ASP/VBScript ADO parameterized query


use like:

Set rs = execute_query(conn, "SELECT custid, custname FROM customers WHERE (somefield > ?) AND (someotherfield < ?)", Array(someValue, someOtherValue));

where conn is a "ADODB.Connection"

Function create_variant_input_parameter(command, name, value)
  Dim param
  ' 12 -> adVariant
  ' 1 -> adParamInput
  Set param = command.CreateParameter(name, 12, 1, 0, value)  
  Set create_variant_input_parameter = param
End Function

Function execute_query(connection, querytext, parameters)
  Dim cmd, i, rs
  Set cmd = Server.CreateObject("ADODB.Command")
  cmd.CommandText = querytext
  ' 1 -> adCmdText
  cmd.CommandType = 1
  For i = 0 To UBound(parameters)
    cmd.Parameters.Append(create_variant_input_parameter(cmd, "", parameters(i)))    
  Next
  Set cmd.ActiveConnection = connection 
  Set rs = cmd.Execute()
  Set execute_query = rs
End Function

ASP/JScript ADO parameterized query

ASP/JScript ADO parameterized query.

use like:

var rs = executeQuery(conn, "SELECT custid, custname FROM customers WHERE somefield > ?", [someValue]);

where conn is a "ADODB.Connection"

Requires that you first include the "adojavas.inc" include file to get definitions for the adXXX constants.

function executeQuery(conn, qry, params) {
  if (arguments.length == 2) { params = []; }
  var cmd, i;
  cmd = Server.CreateObject("ADODB.Command");
  cmd.CommandText = qry;
  cmd.CommandType = adCmdText;
  for (i = 0; i < params.length; i++) {
    cmd.Parameters.Append(cmd.CreateParameter("", adVariant, adParamInput, 0, params[i]));
  }
  cmd.ActiveConnection = conn;
  return cmd.Execute();
}

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed