您的位置:首页 > 移动开发

.NET组件(Microsoft.ApplicationBlocks.Data)

2007-03-12 19:23 453 查看
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对象,该对象包含由某种命令返回的结果集[/b]

 (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)

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息