求一个dataset的第三层类方法
要全部的
包括try catch finally的应用
conn的open 和close 等等调用方法
整个一个三层
呵呵谢谢大家
我自己用的是dataread的三层类方法,,不想用dataread了所以想求一个 dataset的三层
各们帮帮忙啊 嘎嘎
------解决方案--------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
namespace WishDemo.Base
{
/// <summary>
/// 数据服务层的基类
/// </summary>
public abstract class DbObject
{
//存储SQL连接
protected SqlConnection cn;
protected SqlCommand cmd;
//存储连接字符串
private string connectionstring;
/// <summary>
/// 提供连接字符串并实例化基于此字符串的新的连接
/// </summary>
/// <param name= "newConnectionstring "> 连接数据库的连接字符串 </param>
public DbObject( string newConnectionstring )
{
connectionstring = newConnectionstring;
cn = new SqlConnection( connectionstring );
}
/// <summary>
/// 返回只读连接字符串
/// </summary>
protected string ConnectionString
{
get
{
return connectionstring;
}
}
/// <summary>
/// Private routine allowed only by this base class, it automates the task
/// of building a SqlCommand object designed to obtain a return value from
/// the stored procedure.
/// </summary>
/// <param name= "storedProcName "> Name of the stored procedure in the DB, eg. sp_DoTask </param>
/// <param name= "parameters "> Array of IDataParameter objects containing parameters to the stored proc </param>
/// <returns> Newly instantiated SqlCommand instance </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>
/// Builds a SqlCommand designed to return a SqlDataReader, and not
/// an actual integer value.
/// </summary>
/// <param name= "storedProcName "> Name of the stored procedure </param>
/// <param name= "parameters "> Array of IDataParameter objects </param>
/// <returns> </returns>
private SqlCommand BuildQueryCommand(string storedProcName, IDataParameter[] parameters)
{
SqlCommand command = new SqlCommand( storedProcName, cn );
command.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parameter in parameters)
{
command.Parameters.Add( parameter );
}
return command;
}
/// <summary>
/// Runs a stored procedure, can only be called by those classes deriving
/// from this base. It returns an integer indicating the return value of the
/// stored procedure, and also returns the value of the RowsAffected aspect
/// of the stored procedure that is returned by the ExecuteNonQuery method.
/// </summary>
/// <param name= "storedProcName "> Name of the stored procedure </param>