日期:2011-04-20 浏览次数:20473 次
/*****************************************************
* 文 件 名:DBObject.cs
* 功能描述:定义数据层基类。
* 创 建 人:夏春涛 xchuntao@163.com qq:23106676
* 创建时间:2004-08-11 11:05
*****************************************************/
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace XD.XLB.JBC.JBInfo.WebModules.Data
{
/// <summary>
/// 数据层基类,提供对底层数据的基本操作
/// </summary>
public class DBObject
{
private SqlConnection connection;
#region 构造函数
/// <summary>
/// 构造函数,初始化数据连接对象
/// </summary>
public DBObject()
{
string connectionString = ConfigurationSettings.AppSettings.Get("ConnectionString");//从Web.Config中取得的连接字符串
connection = new SqlConnection(connectionString);
}
/// <summary><table style="font-size:12px">
/// <tr><td><b>功能描述</b>:构造函数,根据指定的数据连接字符串,初始化数据连接对象</td></tr>
/// <tr><td><b>创 建 人</b>:夏春涛 </td></tr>
/// <tr><td><b>创建时间</b>:2005-05-28 </td></tr>
/// </table></summary>
/// <param name="newConnectionString">数据连接字符串</param>
public DBObject( string newConnectionString )
{
string connectionString = newConnectionString;
connection = new SqlConnection( connectionString );
}
#endregion
/// <summary>
/// 数据连接对象(只读)
/// </summary>
public SqlConnection Connection
{
get
{
return connection;
}
set
{
connection = value;
}
}
//-----------------------------------------------------------------------------------------
//以下是从《ASP.Net Web站点高级编程》中Copy的(夏春涛)------------------------------------
//-----------------------------------------------------------------------------------------
/// <summary>
/// 创建一个SqlCommand对象,用于获取存储过程的返回值
/// </summary>
/// <param name="storedProcName">存储过程名称</param>
/// <param name="parameters">存储过程的参数对象列表(数组)</param>
/// <returns>SqlCommand对象</returns>
private SqlCommand BuildIntCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = BuildQueryCommand( storedProcName, parameters );
command.Parameters.Add( new SqlParameter ( "ReturnValue",
SqlDbType.Int,
4, /* Size */
ParameterDirection.ReturnValue,
false, /* is nullable */
0, /* byte precision */
0, /* byte scale */
string.Empty,
DataRowVersion.Default,
null ));
return command;
}
/// <summary>
/// 创建一个SqlCommand对象,用于生成SqlDataReader
&n