Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

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

Selected items from a multiple select or checkboxes in VB.net

My co-worker found this code for VB.net that is used to access selected items from check boxes or multiple select boxes. If you've been wondering how to do this, this may help :)

The URL is http://dotnetjunkies.com/weblog/davetrux/archive/2003/11/14/3557.aspx

// The results of a mulitple-select list are also a NameValueCollection
Request.Form.GetValues(i)
// and the individual items are accessed like this:
Request.Form.GetValues(i)(j)

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 »
3 total  XML / RSS feed