Exemple #1
0
 /// <summary>
 /// 为即将执行准备一个命令
 /// </summary>
 /// <param name="conn">SqlConnection对象</param>
 /// <param name="cmd">SqlCommand对象</param>
 /// <param name="isOpenTrans">DbTransaction对象</param>
 /// <param name="cmdType">执行命令的类型(存储过程或T-SQL,等等)</param>
 /// <param name="strSql">存储过程名称或者T-SQL命令行, e.g. Select * from Products</param>
 /// <param name="dbParameter">执行命令所需的sql语句对应参数</param>
 private void PrepareCommand(DbConnection conn, IDbCommand cmd, DbTransaction isOpenTrans, CommandType cmdType, string strSql, params DbParameter[] dbParameter)
 {
     if (conn.State != ConnectionState.Open)
     {
         conn.Open();
     }
     cmd.Connection  = conn;
     cmd.CommandText = strSql; // DbParameters.ToDbSql(cmdText);
     if (isOpenTrans != null)
     {
         cmd.Transaction = isOpenTrans;
     }
     cmd.CommandType = cmdType;
     if (dbParameter != null)
     {
         dbParameter = DbParameterExtension.ToDbParameter(dbParameter);
         foreach (var parameter in dbParameter)
         {
             cmd.Parameters.Add(parameter);
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// 为即将执行准备一个命令
 /// </summary>
 /// <param name="conn">SqlConnection对象</param>
 /// <param name="cmd">SqlCommand对象</param>
 /// <param name="isOpenTrans">DbTransaction对象</param>
 /// <param name="cmdType">执行命令的类型(存储过程或T-SQL,等等)</param>
 /// <param name="strSql">存储过程名称或者T-SQL命令行, e.g. Select * from Products</param>
 /// <param name="dbParameter">执行命令所需的sql语句对应参数</param>
 private void PrepareCommand(DbConnection conn, IDbCommand cmd, DbTransaction isOpenTrans, CommandType cmdType, string strSql, params DbParameter[] dbParameter)
 {
     if (conn.State != ConnectionState.Open)
     {
         conn.Open();
     }
     cmd.Connection     = conn;
     cmd.CommandText    = strSql;
     cmd.CommandTimeout = GlobalContext.SystemConfig.DBCommandTimeout;
     if (isOpenTrans != null)
     {
         cmd.Transaction = isOpenTrans;
     }
     cmd.CommandType = cmdType;
     if (dbParameter != null)
     {
         cmd.Parameters.Clear();
         dbParameter = DbParameterExtension.ToDbParameter(dbParameter);
         foreach (var parameter in dbParameter)
         {
             cmd.Parameters.Add(parameter);
         }
     }
 }