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

2019-08-03 10:38

/// 示例:

/// UpdateDataset(conn, insertCommand, deleteCommand, updateCommand, dataSet, \

///

///

///

///

/// ///

public static void UpdateDataset(SqlCommand insertCommand, SqlCommand deleteCommand, SqlCommand updateCommand, DataSet dataSet, string tableName) ...{ if(

insertCommand

==

null null null

) ) )

throw throw throw

new new new

ArgumentNullException( \ if( deleteCommand == ArgumentNullException( \ if(

updateCommand

==

ArgumentNullException( \

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

// 创建SqlDataAdapter,当操作完成后释放.

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

// 设置数据适配器命令

dataAdapter.UpdateCommand = updateCommand; dataAdapter.InsertCommand = insertCommand; dataAdapter.DeleteCommand = deleteCommand;

// 更新数据集改变到数据库

dataAdapter.Update (dataSet, tableName);

// 提交所有改变到数据集. dataSet.AcceptChanges(); } }

#endregion

CreateCommand 创建一条SqlCommand命令#region CreateCommand 创建一条SqlCommand命令 /**////

/// 创建SqlCommand命令,指定数据库连接对象,存储过程名和参数. ///

/// /// 示例:

/// SqlCommand command = CreateCommand(conn, \\

///

/// ///

/// /// 返回SqlCommand命令

public static SqlCommand CreateCommand(SqlConnection connection, string spName, params string[] sourceColumns) ...{

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

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

// 创建命令

SqlCommand cmd = new SqlCommand( spName, connection ); cmd.CommandType = CommandType.StoredProcedure;

// 如果有参数值

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

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

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

// 将源表的列到映射到DataSet命令中.

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

commandParameters[index].SourceColumn = sourceColumns[index];

// Attach the discovered parameters to the SqlCommand object AttachParameters (cmd, commandParameters); }

return cmd; }

#endregion

ExecuteNonQueryTypedParams 类型化ExecuteNonQueryTypedParams 类型化参数(DataRow)

(DataRow)#region

=

/**////

/// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回受影响的行数.

///

/// ///

///

/// 返回影响的行数

public static int ExecuteNonQueryTypedParams(String connectionString, String spName, DataRow dataRow)

...{

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

if( spName == null || spName.Length ArgumentNullException( \

// 如果row有值,存储过程必须初始化.

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

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

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

// 分配参数值

AssignParameterValues(commandParameters, dataRow);

return SqlHelper.ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters); } else ...{

return

CommandType.StoredProcedure, spName); } }

/**////

/// 执行指定连接数据库连接对象的存储过程,使用DataRow做为参数值,返回受影响的行数.

///

/// ///

///

SqlHelper.ExecuteNonQuery(connectionString,

=

==

0

)

throw

new

/// 返回影响的行数

public static int ExecuteNonQueryTypedParams(SqlConnection connection, String spName, DataRow dataRow) ...{

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

spName

==

null

||

spName.Length

==

0

)

throw

new

ArgumentNullException( \

// 如果row有值,存储过程必须初始化.

if (dataRow != null && dataRow.ItemArray.Length > 0)

...{

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

SqlParameter[]

commandParameters

=

SqlHelperParameterCache.GetSpParameterSet(connection, spName);

// 分配参数值

AssignParameterValues(commandParameters, dataRow); return } else ...{

return

CommandType.StoredProcedure, spName); }

}

/**////

/// 执行指定连接数据库事物的存储过程,使用DataRow做为参数值,返回受影响的行数.

///

/// ///

/// /// 返回影响的行数

public static int ExecuteNonQueryTypedParams(SqlTransaction transaction, String spName, DataRow dataRow) ...{

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.\

SqlHelper.ExecuteNonQuery(connection,

CommandType.StoredProcedure, spName, commandParameters);

SqlHelper.ExecuteNonQuery(connection,

if( spName == null || spName.Length == 0 ) throw new

ArgumentNullException( \

// Sf the row has values, the store procedure parameters must be initialized if (dataRow != null && dataRow.ItemArray.Length > 0)

...{

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

SqlParameter[]

// 分配参数值

AssignParameterValues(commandParameters, dataRow);

return SqlHelper.ExecuteNonQuery(transaction, CommandType.StoredProcedure, spName, commandParameters); } else ...{ return

CommandType.StoredProcedure, spName);

} }

#endregion

ExecuteDatasetTypedParams 类型ExecuteDatasetTypedParams 类型化参数(DataRow)

SqlHelper.ExecuteNonQuery(transaction, commandParameters

=

SqlHelperParameterCache.GetSpParameterSet(transaction.Connection, spName);

化参数(DataRow)#region

/**////

/// 执行指定连接数据库连接字符串的存储过程,使用DataRow做为参数值,返回DataSet.

///

/// ///

/// /// 返回一个包含结果集的DataSet.

public static DataSet ExecuteDatasetTypedParams(string connectionString, String spName, DataRow dataRow)

...{

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

spName

==

null

||

spName.Length

==

0

)

throw

new

ArgumentNullException( \

//如果row有值,存储过程必须初始化.


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

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

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

马上注册会员

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