카테고리 없음2009. 2. 24. 14:06

 아무도 안해서 ㅡㅡ; 다 취소~
사용 하는거 발표 ;;

 return 값에 따른 MssqlHelper

 public static int ExecuteNonQuery(SqlConnection connection, string commandText,
                                                                params SqlParameter[] commandParameters)

        {
            
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = connection;
            cmd.CommandText = commandText;
            cmd.CommandType = CommandType.Text;

            if (commandParameters != null)
                foreach (SqlParameter p in commandParameters)
                    cmd.Parameters.Add(p);

            int result = cmd.ExecuteNonQuery();
            cmd.Parameters.Clear();

            return result;
        }


1. 숫자 : 조회 Count
2. DataSet : 데이터
3. XML : 데이터
4. DataRow : 데이터
5. MsSqlDataReader : 데이터
6. object
7. 특정 class
8. 특정 Collection

위의 방식 외 여러가지 상황이 있겠지만 대략 이렇게 생각 해 봤습니다.



Posted by penguindori
2009/Study 모임 B조2009. 2. 24. 14:03
#region ExecuteScalar

  /// <summary>
  /// Execute a single command against a MySQL database.
  /// </summary>
  /// <param name="connectionString">Settings to use for the update</param>
  /// <param name="commandText">Command text to use for the update</param>
  /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
  public static object ExecuteScalar(string connectionString, string commandText)
  {
   //pass through the call providing null for the set of MySqlParameters
   return ExecuteScalar(connectionString, commandText, (MySqlParameter[])null);
  }

  /// <summary>
  /// Execute a single command against a MySQL database.
  /// </summary>
  /// <param name="connectionString">Settings to use for the command</param>
  /// <param name="commandText">Command text to use for the command</param>
  /// <param name="commandParameters">Parameters to use for the command</param>
  /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
  public static object ExecuteScalar(string connectionString, string commandText, params MySqlParameter[] commandParameters)
  {
   //create & open a SqlConnection, and dispose of it after we are done.
   using (MySqlConnection cn = new MySqlConnection(connectionString))
   {
    cn.Open();

    //call the overload that takes a connection in place of the connection string
    return ExecuteScalar(cn, commandText, commandParameters);
   }
  }

  /// <summary>
  /// Execute a single command against a MySQL database.
  /// </summary>
  /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
  /// <param name="commandText">Command text to use for the command</param>
  /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
  public static object ExecuteScalar(MySqlConnection connection, string commandText)
  {
   //pass through the call providing null for the set of MySqlParameters
   return ExecuteScalar(connection, commandText, (MySqlParameter[])null);
  }

  /// <summary>
  /// Execute a single command against a MySQL database.
  /// </summary>
  /// <param name="connection"><see cref="MySqlConnection"/> object to use</param>
  /// <param name="commandText">Command text to use for the command</param>
  /// <param name="commandParameters">Parameters to use for the command</param>
  /// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
  public static object ExecuteScalar(MySqlConnection connection, string commandText, params MySqlParameter[] commandParameters)
  {
   //create a command and prepare it for execution
   MySqlCommand cmd = new MySqlCommand();
   cmd.Connection = connection;
   cmd.CommandText = commandText;
   cmd.CommandType = CommandType.Text;
   
   if (commandParameters != null)
    foreach (MySqlParameter p in commandParameters)
     cmd.Parameters.Add( p );
   
   //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();
   return retval;
   
  }

  #endregion
 }
}


http://www.koders.com/csharp/fid01EA450A209966FCB52CA84DABB208DEF807D142.aspx
Posted by penguindori