Ejemplo n.º 1
0
        /// <summary>
        /// Gets the parameters for <paramref name="command"/>.
        /// </summary>
        /// <param name="command">The <see cref="System.Data.SqlClient.SqlCommand"/> for witch to get the parameters</param>
        internal void GetCommandParameters(SqlCommand command)
        {
            //First check to see if there is cached parameter for this command
            if (ParameterCache.IsParametersCached(command))
            {
                //get the parameters from cache
                GetParametersFromCache(command);
            }
            else
            {
                //create a new connection to derive the parameters
                try
                {
                    SqlConnection connection = new SqlConnection(mConnectionString);
                    command.Connection  = connection;
                    command.Transaction = null;
                    connection.Open();

                    SqlCommandBuilder.DeriveParameters(command);

                    command.Connection.Close();
                    command.Connection  = mSqlConnection;
                    command.Transaction = mSqlTransaction;

                    //Cache the parameters for later use
                    ParameterCache.CacheParameters(command);
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the parameters for the <paramref name="command"/> from the parameters cache
 /// </summary>
 /// <param name="command">The <see cref="System.Data.SqlClient.SqlCommand"/> for witch to get the parameters</param>
 private static void GetParametersFromCache(SqlCommand command)
 {
     IDataParameter[] parameters = ParameterCache.GetCachedParameters(command);
     for (int i = 0, j = parameters.Length; i < j; i++)
     {
         command.Parameters.Add(parameters[i]);
     }
 }