/// <summary>
/// 执行参数查询
/// </summary>
/// <param name="cmd">数据库执行命令</param>
/// <param name="conn">数据库链接命令</param>
/// <param name="trans">事务</param>
/// <param name="cmdText">查询语句</param>
/// <param name="cmdParms">查询参数</param>
/// <returns></returns>
private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, string cmdText, SqlParameter[] cmdParms)
{
if (conn.State != ConnectionState.Open)
conn.Open();
cmd.Connection = conn;
cmd.CommandText = cmdText;
if (trans != null)
cmd.Transaction = trans;
cmd.CommandType = CommandType.Text;//cmdType;
if (cmdParms != null)
{
foreach (SqlParameter parameter in cmdParms)
{
if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
(parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
cmd.Parameters.Add(parameter);
}
}
}