SqlParameter[] param = new SqlParameter[] { };
List<SqlParameter> sqlParameterList = new List<SqlParameter>(); //这里是重点,要拿脑子记一下。
if (!string.IsNullOrEmpty(cpId))
{
sql += " and a.cpId =@cpId";
sqlParameterList.Add(new SqlParameter { ParameterName = "@cpId", Value = cpId, SqlDbType = SqlDbType.VarChar, Size = 20 });
}
if (!string.IsNullOrEmpty(cpName))
{
sql += " and b.name like @cpName";
sqlParameterList.Add(new SqlParameter { ParameterName = "@cpName", Value = '%' + cpName + '%', SqlDbType = SqlDbType.VarChar, Size = 20 });
}
if (!string.IsNullOrEmpty(status))
{
sql += " and b.status = @status";
sqlParameterList.Add(new SqlParameter { ParameterName = "@status", Value = status, SqlDbType = SqlDbType.Int, Size = 10 });
}
//sql += " order by createdatetime desc ";
param = sqlParameterList.ToArray();