public List<PD_Bank> GetListBySearch(string cRenYuanBianHao, string cXingMing, string dKaiShiRiQi, string dJieShuRiQi) { //定义参数集合 List<SqlParameter> paramList = new List<SqlParameter>(); //定义查询SQL语句 string sql = "select a.ID, a.人员编号, b.姓名, a.开始日期, a.结束日期, a.银行账户类型, a.银行, a.账户名称, a.账号, a.备注, a.更改者, a.更改日期 from PD_Bank a"; sql += $" inner join pd_basic b on a.人员编号 = b.人员编号"; sql += " where b.结束日期 = '9999.12.31'"; sql += " and 1 = 1"; //根据条件添加查询参数 if (cRenYuanBianHao != null && cRenYuanBianHao.Length > 0) { sql += " and a.人员编号 like @人员编号"; paramList.Add(new SqlParameter("@人员编号", $"%{cRenYuanBianHao}%")); } if (cXingMing != null && cXingMing.Length > 0) { sql += " and b.姓名 like @姓名"; paramList.Add(new SqlParameter("@姓名", $"%{cXingMing}%")); } if (dKaiShiRiQi != null && dKaiShiRiQi.Length > 0) { sql += " and a.开始日期 >= @开始日期"; paramList.Add(new SqlParameter("@开始日期", dKaiShiRiQi)); } if (dJieShuRiQi != null && dJieShuRiQi.Length > 0) { sql += " and a.结束日期 <= @结束日期"; paramList.Add(new SqlParameter("@结束日期", dJieShuRiQi)); } sql += " order by a.人员编号, a.结束日期 desc"; SqlDataReader reader = SQLHelper.GetReader(sql, paramList.ToArray()); List<PD_Bank> list = new List<PD_Bank>(); while (reader.Read()) { list.Add(new PD_Bank() { ID = (int)reader["ID"], 人员编号 = reader["人员编号"].ToString(), 开始日期 = reader["开始日期"] is DBNull ? null : (DateTime?)reader["开始日期"], 结束日期 = reader["结束日期"] is DBNull ? null : (DateTime?)reader["结束日期"], 银行账户类型 = reader["银行账户类型"].ToString(), 银行 = reader["银行"].ToString(), 账户名称 = reader["账户名称"].ToString(), 账号 = reader["账号"].ToString(), 备注 = reader["备注"].ToString(), 更改者 = reader["更改者"].ToString(), 更改日期 = reader["更改日期"] is DBNull ? null : (DateTime?)reader["更改日期"] }); } reader.Close(); return list; }