完整SqlHelper类详细中文注释(9)

2019-08-03 10:38

commandParameters);

}

/**////

/// 执行指定数据库连接对象的命令,映射数据表并填充数据集,指定存储过程参数值.

///

///

/// 此方法不提供访问存储过程输出参数和返回值参数. ///

/// 示例:

/// FillDataset(conn, \ ///

/// ///

/// ///

///

/// public static void FillDataset(SqlConnection connection, string spName, DataSet dataSet, string[] tableNames, params object[] parameterValues) ...{

if ( connection == null ) throw new ArgumentNullException( \ if (dataSet == null ) throw new ArgumentNullException( \

if( spName == null || spName.Length == 0 ) throw ArgumentNullException( \

// 如果有参数值

if ((parameterValues != null) && (parameterValues.Length > 0)) ...{

// 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. ()

SqlParameter[] commandParameters SqlHelperParameterCache.GetSpParameterSet(connection, spName);

// 给存储过程参数赋值

AssignParameterValues(commandParameters, parameterValues);

// 调用重载方法

FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames, commandParameters); }

= new

else

...{

// 没有参数值

FillDataset(connection, CommandType.StoredProcedure, spName, dataSet, tableNames); } }

/**////

/// 执行指定数据库事务的命令,映射数据表并填充数据集.

///

/// /// 示例:

/// FillDataset(trans, CommandType.StoredProcedure, \ds, new

string[] ...{\ ///

///

/// /// /// /// public static commandType,

void

FillDataset(SqlTransaction

transaction,

CommandType

string commandText,

DataSet dataSet, string[] tableNames)

...{

FillDataset (transaction, commandType, commandText, dataSet, tableNames, null); }

/**////

/// 执行指定数据库事务的命令,映射数据表并填充数据集,指定参数. ///

/// /// 示例:

/// FillDataset(trans, CommandType.StoredProcedure, \ds, new string[] ...{\ ///

///

/// /// /// ///

/// 用户定义的表名 (可有是实际的表名.)

///

///

public commandType,

string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters) ...{

FillDataset(transaction.Connection, transaction, commandType, commandText, dataSet, tableNames, commandParameters); }

/**////

/// 执行指定数据库事务的命令,映射数据表并填充数据集,指定存储过程参数值. ///

///

/// 此方法不提供访问存储过程输出参数和返回值参数. ///

/// 示例:

/// FillDataset(trans, \

///

/// ///

///

static

void

FillDataset(SqlTransaction

transaction,

CommandType

///

///

/// public static void FillDataset(SqlTransaction transaction, string spName, DataSet dataSet, string[] tableNames, params object[] parameterValues)

...{

if( transaction == null ) throw new ArgumentNullException( \ if( transaction != null && transaction.Connection == null ) throw new ArgumentException( \transaction was rollbacked or commited, please provide an open transaction.\

if( dataSet == null ) throw new ArgumentNullException( \

if( spName == null || spName.Length == 0 ) throw ArgumentNullException( \

// 如果有参数值

if ((parameterValues != null) && (parameterValues.Length > 0)) ...{

new

// 从缓存中加载存储过程参数,如果缓存中不存在则从数据库中检索参数信息并加载到缓存中. ()

SqlParameter[] commandParameters

SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);

// 给存储过程参数赋值

AssignParameterValues(commandParameters, parameterValues);

// 调用重载方法

FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames, commandParameters); }

else ...{

// 没有参数值

FillDataset(transaction, CommandType.StoredProcedure, spName, dataSet, tableNames);

} }

/**////

/// [私有方法][内部调用]执行指定数据库连接对象/事务的命令,映射数据表并填充数据集,DataSet/TableNames/SqlParameters. ///

/// /// 示例:

/// FillDataset(conn, trans, CommandType.StoredProcedure, \ds, new string[] ...{\ ///

///

///

/// /// /// ///

///

///

private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType,

string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters) ...{

=

if( connection == null ) throw new ArgumentNullException( \ if( dataSet == null ) throw new ArgumentNullException( \

// 创建SqlCommand命令,并进行预处理 SqlCommand command = new SqlCommand(); bool mustCloseConnection = false; PrepareCommand(command,

connection,

transaction,

commandType,

commandText, commandParameters, out mustCloseConnection );

// 执行命令

using( SqlDataAdapter dataAdapter = new SqlDataAdapter(command) ) ...{

// 追加表映射

if (tableNames != null && tableNames.Length > 0) ...{

string tableName = \

for (int index=0; index < tableNames.Length; index++) ...{

if( tableNames[index] == null || tableNames[index].Length == 0 ) throw new ArgumentException( \was provided as null or empty string.\

dataAdapter.TableMappings.Add(tableName, tableNames[index]); tableName += (index + 1).ToString(); }

}

// 填充数据集使用默认表名称 dataAdapter.Fill(dataSet);

// 清除参数,以便再次使用. command.Parameters.Clear(); }

if( mustCloseConnection ) connection.Close(); }

#endregion

UpdateDataset 更新数据集#region UpdateDataset 更新数据集 /**////

/// 执行数据集更新到数据库,指定inserted, updated, or deleted命令. ///

///


完整SqlHelper类详细中文注释(9).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:关于印发启用2000国家坐标系实施方案的通知

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: