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

来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-01 15:02 点击:
    // Call the overload that takes an array of SqlParameters
    return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName, commandParameters);
   }
   else
   {
    // Otherwise we can just call the SP without params
    return ExecuteScalar(connectionString, CommandType.StoredProcedure, spName);
   }
  }

  /// <summary>
  /// Execute a SqlCommand (that returns a 1x1 resultset and takes no parameters) against the provided SqlConnection.
  /// </summary>
  /// <remarks>
  /// e.g.: 
  ///  int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount");
  /// </remarks>
  /// <param name="connection">A valid SqlConnection</param>
  /// <param name="commandType">The CommandType (stored procedure, text, etc.)</param>
  /// <param name="commandText">The stored procedure name or T-SQL command</param>
  /// <returns>An object containing the value in the 1x1 resultset generated by the command</returns>
  public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText)
  {
   // Pass through the call providing null for the set of SqlParameters
   return ExecuteScalar(connection, commandType, commandText, (SqlParameter[])null);
  }

  /// <summary>
  /// Execute a SqlCommand (that returns a 1x1 resultset) against the specified SqlConnection
  /// using the provided parameters.
  /// </summary>
  /// <remarks>
  /// e.g.: 
  ///  int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));
  /// </remarks>
  /// <param name="connection">A valid SqlConnection</param>
  /// <param name="commandType">The CommandType (stored procedure, text, etc.)</param>
  /// <param name="commandText">The stored procedure name or T-SQL command</param>
  /// <param name="commandParameters">An array of SqlParamters used to execute the command</param>
  /// <returns>An object containing the value in the 1x1 resultset generated by the command</returns>
  public static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
  {
   if( connection == null ) throw new ArgumentNullException( "connection" );

   // Create a command and prepare it for execution
   SqlCommand cmd = new SqlCommand();

   bool mustCloseConnection = false;
   PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters, out mustCloseConnection );
       
   // Execute the command & return the results
   object retval = cmd.ExecuteScalar();
       
   // Detach the SqlParameters from the command object, so they can be used again
   cmd.Parameters.Clear();

   if( mustCloseConnection )
    connection.Close();

   return retval;
  }

  /// <summary>
  /// Execute a stored proc

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

    推荐热点

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

    豫ICP备11007008号-1