欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

2012年计算机二级ACCESS的参数化查询(5)

程序员文章站 2022-04-27 20:35:07
...

string Sql { get { return sql; } set { sql = value; } } int T { get { return t; } set { t = value; } } object V { get { return v; } set { v = value; } } } } //调用方法 //accselect acc = new accselect(); //acc.sql = select * from dtt where

string Sql

  {

  get

  {

  return sql;

  }

  set

  {

  sql = value;

  }

  }

  int T

  {

  get

  {

  return t;

  }

  set

  {

  t = value;

  }

  }

  object V

  {

  get

  {

  return v;

  }

  set

  {

  v = value;

  }

  }

  }

  }

  //调用方法

  //accselect acc = new accselect();

  //acc.sql = "select * from dtt where d_id=?";

  //acc.t = 10;

  //acc.v = 1;

  //OleDbDataReader oda = acc.getOdd(OleDbType.VarChar);

  //Repeater1.DataSource = oda;

  //Repeater1.DataBind();

  function acc_sql(sql,adotype,adodct,strlong,values)

  dim connstring,mycmd,myrs,conn

  connString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db1.mdb")

  set conn = Server.CreateObject("Adodb.Connection")

  conn.ConnectionString = connString

  conn.open()

  set mycmd = Server.CreateObject("ADODB.Command")

  mycmd.ActiveConnection=conn

  mycmd.CommandText=sql

  mycmd.Prepared = true

  set mypar = mycmd.CreateParameter("temp",adotype,adodct,strlong,values)

  mycmd.Parameters.Append mypar

  set myrs = mycmd.Execute

  set acc_sql=myrs

  end function

  ’调用方法

  ’dim rs

  ’sql="select * from users where id=? order by id"

  ’set rs=acc_sql(sql,3,1,4,1)

  ’if not rs.eof then

  ’response.Write(rs(1))

  ’end if