ACCESS的参数化查询,附VBSCRIPT(ASP)和C#(ASP.NET)函数
更新时间:2008年01月11日 17:27:48 作者:
ACCESS的参数化查询,附VBSCRIPT(ASP)和C#(ASP.NET)函数
---------------------------------------------------------------------------------
附我写的C#类,和VBSCRIPT函数,希望对大家有帮助
复制代码 代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.OleDb;
namespace acc_select
{
/// <summary>
/// accselect 的摘要说明
/// </summary>
public class accselect
{
//"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\dq\db1.mdb"
private string conn = ConfigurationManager.ConnectionStrings["tsingConnectionString"].ToString();
public string sql = string.Empty;
public int t = 4;
public object v = null;
public accselect()
{
}
/// <summary>
/// 构造函数,传递ACC参数查询语句
/// </summary>
/// <param name="strsql">strsql字符型</param>
public accselect(string strsql)
{
sql = strsql;
}
/// <summary>
/// 构造函数,传递ACC参数查询语句
/// </summary>
/// <param name="strsql">参数查询语句</param>
/// <param name="total">字节数</param>
public accselect(string strsql, int total)
{
sql = strsql;
t = total;
}
/// <summary>
/// 构造函数
/// </summary>
/// <param name="strsql">参数查询语句</param>
/// <param name="total">字节数</param>
/// <param name="value">OBJECT值</param>
public accselect(string strsql, int total, object value)
{
sql = strsql;
t = total;
v = value;
}
/// <summary>
/// getOdd方法返回OleDbDataReader
/// </summary>
/// <param name="odt">定义OleDbType类型</param>
/// <returns></returns>
public OleDbDataReader getOdd(OleDbType odt)
{
OleDbConnection conns = new OleDbConnection(this.conn);
OleDbCommand cmd = new OleDbCommand(this.sql, conns);
OleDbParameter parm = new OleDbParameter("temp", odt, this.t);
parm.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parm);
cmd.Parameters[0].Value = this.v;
conns.Open();
OleDbDataReader oda = cmd.ExecuteReader();
cmd.Dispose();
return oda;
}
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
------------------------------------------------------------------------------------
完! 谢谢大家!
相关文章
ADODB连接access是出现 80004005 错误的解决方法
今天我写的程序放到客户的机器上,一运行就出现Selected Collating Sequence Not Supported 80004005这个错误。经过google一番后,解决如下。2009-09-09
最新评论