.NET组件(Microsoft.ApplicationBlocks.Data)

Microsoft.ApplicationBlocks.Data是一个.NET组件,包含优化的数据访问代码.

它主要包括SqlHelper类和SqlHelperParameterCache类。

它可以实现:

       1.调用存储过程或SQL文本命令。

       2.指定参数详细信息。

       3.返回SqlDataReaderDataSet、或XmlReader对象。

 

SqlHelper

用于通过一组静态方法来封装数据访问功能,但该类不能被继承或实例化。

具体方法如下:

public static System.Data.SqlClient.SqlCommand  CreateCommand

(System.Data.SqlClient.SqlConnection connection, string spName, params string [] sourceColumns)

 

public static System.Data.DataSet ExecuteDataset

//返回DataSet对象,该对象包含由某种命令返回的结果集

 (System.Data.SqlClient.SqlTransaction transaction, string spName, params object [] parameterValues)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText)

(System.Data.SqlClient.SqlConnection connection, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText)

(string connectionString, string spName, params object[] parameterValues)

(string connectionString, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(string connectionString, System.Data.CommandType commandType, string commandText)

 

public static System.Data.DataSet ExecuteDatasetTypedParams

(System.Data.SqlClient.SqlTransaction transaction, string spName, System.Data.DataRow dataRow)

(System.Data.SqlClient.SqlConnection connection, string spName, System.Data.DataRow dataRow)

(string connectionString, string spName, System.Data.DataRow dataRow)

 

public static int ExecuteNonQuery

//用于执行不返回任何行和值的命令。这些命令通常用于数据库的更新、但也可用于返回存储过程的输出参数

(System.Data.SqlClient.SqlTransaction transaction, string spName, params object [] parameterValues)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText)

(System.Data.SqlClient.SqlConnection connection, string spName, params object [] parameterValues)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText)

(string connectionString, string spName, params object[] parameterValues)

(string connectionString, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

(string connectionString, System.Data.CommandType commandType, string commandText)

 

public static int ExecuteNonQueryTypedParams

(System.Data.SqlClient.SqlTransaction transaction, string spName, System.Data.DataRow dataRow)

(System.Data.SqlClient.SqlConnection connection, string spName, System.Data.DataRow dataRow)

(string connectionString, string spName, System.Data.DataRow dataRow)

 

public static System.Data.SqlClient.SqlDataReader ExecuteReader

//用于返回SqlDataReader对象,该对象包含由某一命令返回的结果集

(System.Data.SqlClient.SqlTransaction transaction, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText)

(System.Data.SqlClient.SqlConnection connection, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText)

(string connectionString, string spName, params object[] parameterValues)

(string connectionString, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

(string connectionString, System.Data.CommandType commandType, string commandText)

 

public static System.Data.SqlClient.SqlDataReader ExecuteReaderTypedParams

(System.Data.SqlClient.SqlTransaction transaction, string spName, System.Data.DataRow dataRow)

(System.Data.SqlClient.SqlConnection connection, string spName, System.Data.DataRow dataRow)

(string connectionString, string spName, System.Data.DataRow dataRow)

 

public static object ExecuteScalar

//返回一个值,该值始终是该命令返回的第一行的第一列

(System.Data.SqlClient.SqlTransaction transaction, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText)

(System.Data.SqlClient.SqlConnection connection, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter [] commandParameters)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText)

(string connectionString, string spName, params object[] parameterValues)

(string connectionString, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

(string connectionString, System.Data.CommandType commandType, string commandText)

public static object ExecuteScalarTypedParams

(System.Data.SqlClient.SqlTransaction transaction, string spName, System.Data.DataRow dataRow)

(System.Data.SqlClient.SqlConnection connection, string spName, System.Data.DataRow dataRow)

(string connectionString, string spName, System.Data.DataRow dataRow)

 

public static void FillDataset

(System.Data.SqlClient.SqlTransaction transaction, string spName, System.Data.DataSet dataSet, string[] tableNames, params object[] parameterValues)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, System.Data.DataSet dataSet, string[] tableNames, params System.Data.SqlClient.SqlParameter[] commandParameters)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, System.Data.DataSet dataSet, string[] tableNames)

(System.Data.SqlClient.SqlConnection connection, string spName, System.Data.DataSet dataSet, string[] tableNames, params object[] parameterValues)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, System.Data.DataSet dataSet, string[] tableNames, params System.Data.SqlClient.SqlParameter[] commandParameters)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, System.Data.DataSet dataSet, string[] tableNames)

(string connectionString, string spName, System.Data.DataSet dataSet, string[] tableNames, params object[] parameterValues)

(string connectionString, System.Data.CommandType commandType, string commandText, System.Data.DataSet dataSet, string[] tableNames, params System.Data.SqlClient.SqlParameter[] commandParameters)

(string connectionString, System.Data.CommandType commandType, string commandText, System.Data.DataSet dataSet, string[] tableNames)

 

public static void UpdateDataset

(System.Data.SqlClient.SqlCommand insertCommand, System.Data.SqlClient.SqlCommand deleteCommand, System.Data.SqlClient.SqlCommand updateCommand, System.Data.DataSet dataSet, string tableName)

 

public static System.Xml.XmlReader ExecuteXmlReader

//返回FOR XML查询的XML片段

(System.Data.SqlClient.SqlTransaction transaction, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

(System.Data.SqlClient.SqlTransaction transaction, System.Data.CommandType commandType, string commandText)

(System.Data.SqlClient.SqlConnection connection, string spName, params object[] parameterValues)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

(System.Data.SqlClient.SqlConnection connection, System.Data.CommandType commandType, string commandText)

 

public static System.Xml.XmlReader ExecuteXmlReaderTypedParams

(System.Data.SqlClient.SqlTransaction transaction, string spName, System.Data.DataRow dataRow)

(System.Data.SqlClient.SqlConnection connection, string spName, System.Data.DataRow dataRow)

 

SqlHelperParameterCache

具体方法如下:

public static void CacheParameterSet   

//用于将SqlParameters数组存储到缓存中

//此方法通过将连接字符串和命令文本连接起来创建一个,然后将参数数组存储在Hashtable

(string connectionString, string commandText, params System.Data.SqlClient.SqlParameter[] commandParameters)

 

public static System.Data.SqlClient.SqlParameter[] GetCachedParameterSet

//用于检索缓存的参数数组的副本

(string connectionString, string commandText)

 

public static System.Data.SqlClient.SqlParameter[] GetSpParameterSet

//用于检索指定存储过程的相应参数(首先查询一次数据库,然后缓存结果以便将来查询)

//如果这些参数尚未被缓存,则使用.NETSqlCommandBuilder类从内部检索,并将这些添加到缓存中

(string connectionString, string spName, bool includeReturnValueParameter)

(string connectionString, string spName)

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值