ASP提供服务器组件中哪个实现数据库读取或存取数据?
追问:content linking组件ado组件
filesystem组件
ad rotator组件
哪个是的?针对我上面的问题?
追问:content linking组件ado组件
filesystem组件
ad rotator组件
哪个是的?针对我上面的问题?
答案:使用Adodb.Connection创建数据库连接对象使用Adodb.recordset创建数据集对象
db="database/nodata.mdb" '数据库文件的位置
Set conn = Server.CreateObject("ADODB.Connection") //创建数据库连接对象
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db) //数据库连接字符串
conn.Open connstr //打开数据库
set rsConfig=server.CreateObject("adodb.recordset") //创建数据集对象,用于读取和存储数据库
rsConfig.open "select * from setting",conn,1,3 //打开指定的数据表,
if not rsConfig.eof then //判断是否有对象
System=rsConfig("SysVar") //保存到变量
else
System="NoConfig"
end if
rsConfig.AddNew() //添加数据集对象,保存到数据库rsConfig("SysVar")
rsConfig.Update() //保存到数据库
set rsConfig=nothing //清空数据集对象
public class SQLServer
{
private string _Message = null;
/// <summary>
/// 信息
/// </summary>
public string Message
{
get { return _Message; }
set { _Message = value; }
}private SqlConnection conn = null; //数据库连接,用于事务
private SqlTransaction trans = null;//数据库事务
/// <summary>
/// 连接字符串
/// </summary>
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["sqlserver"].ConnectionString;#region 一般操作
/// <summary>
/// 调用存储过程
/// </summary>
/// <param name="name"></param>
/// <param name="paramList"></param>
/// <returns>-1:失败</returns>
public int CallProcedure(string name, System.Data.Common.DbParameter[] paramList)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = this.connString;SqlCommand command = new SqlCommand(name);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.AddRange(paramList);
command.Connection = conn;
try
{
conn.Open();
return command.ExecuteNonQuery();
}
catch (SqlException ex)
{
this._Message = ex.Message;
return -1;
}
finally
{
conn.Close();
}
}
/// <summary>
/// 获取结果集
/// </summary>
/// <param name="selectSQL"></param>
/// <returns></returns>
public DataTable Select(string selectSQL)
{
DataTable ds = new DataTable();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = this.connString;
SqlDataAdapter adapter = new SqlDataAdapter(selectSQL, conn);
try
{
conn.Open();
adapter.Fill(ds);
}
catch (SqlException ex)
{
this._Message = ex.Message;
}
finally
{
conn.Close();
}
return ds;
}
/// <summary>
/// 选取单个值
/// </summary>
/// <param name="selectSQL"></param>
/// <returns></returns>
public object SelectValue(string selectSQL)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = this.connString;
SqlCommand command = new SqlCommand(selectSQL, conn);
try
&nbs