程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#基礎知識 >> C#完成C/S架構下地TREEVIEW只輸入表名,父ID,節點ID,節點名就得到樹型結構(3)

C#完成C/S架構下地TREEVIEW只輸入表名,父ID,節點ID,節點名就得到樹型結構(3)

編輯:C#基礎知識
    // 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.Paramet

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一頁  >> 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved