C#实现C/S架构下的TREEVIEW只输入表名,父ID,节点ID,节点名就得到树型结构(2)

来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-01 10:03 点击:
 /// <summary>
  /// Execute a stored procedure via a SqlCommand (that returns a resultset) against the specified SqlConnection
  /// using the provided parameter values.  This method will query the database to discover the parameters for the
  /// stored procedure (the first time each stored procedure is called), and assign the values based on parameter order.
  /// </summary>
  /// <remarks>
  /// This method provides no access to output parameters or the stored procedure's return value parameter.
  ///
  /// e.g.: 
  ///  DataSet ds = ExecuteDataset(conn, "GetOrders", 24, 36);
  /// </remarks>
  /// <param name="connection">A valid SqlConnection</param>
  /// <param name="spName">The name of the stored procedure</param>
  /// <param name="parameterValues">An array of objects to be assigned as the input values of the stored procedure</param>
  /// <returns>A dataset containing the resultset generated by the command</returns>
  public static DataSet ExecuteDataset(SqlConnection connection, string spName, params object[] parameterValues)
  {
   if( connection == null ) throw new ArgumentNullException( "connection" );
   if( spName == null || spName.Length == 0 ) throw new ArgumentNullException( "spName" );

   // If we receive parameter values, we need to figure out where they go
   if ((parameterValues != null) && (parameterValues.Length > 0))
   {
    // Pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
    SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connection, spName);

    // Assign the provided values to these parameters based on parameter order
    AssignParameterValues(commandParameters, parameterValues);

    // Call the overload that takes an array of SqlParameters
    return ExecuteDataset(connection, CommandType.StoredProcedure, spName, commandParameters);
   }
   else
   {
    // Otherwise we can just call the SP without params
    return ExecuteDataset(connection, CommandType.StoredProcedure, spName);
   }
  }

  /// <summary>
  /// Execute a SqlCommand (that returns a resultset and takes no parameters) against the provided SqlTransaction.
  /// </summary>
  /// <remarks>
  /// e.g.: 
  ///  DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure, "GetOrders");
  /// </remarks>
  /// <param name="transaction">A valid SqlTransaction</param>
  /// <param name="commandType">The CommandType (stored procedure, text, etc.)</param>
  /// <param name="commandText">The stored procedure name or T-SQL command</param>
  /// <returns>A dataset containing the resultset generated by the command</returns>
  public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText)
  {
   // Pass through the call providing null for the set of SqlParameters
   return ExecuteDataset(transaction, commandType, commandText, (SqlParameter[])null);
  }
  
 &

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • 用C#制作屏幕捕获程序
    • .NET程序员项目开发必知必会—Dev环境中的集成测试用例执行时上
    • 遍历ArrayList易犯错误
    • C#对XML操作:一个处理XML文件的类(1)
    • .NET简谈反射(动态调用)
    • 使用C#编写LED样式时钟控件
    • DataList嵌套问题 如何删除内层子DataList的记录
    • 怎样用C#实现完整文档打印功能
    • .NET简谈自定义事务资源管理器
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1