小弟我最近在做一个项目,正在做多条件查询,当什么条件都不选时,能显示正确的结果。但我选了一个条件(正确的条件)后,它就显示没有符合的内容。
具体程序如下:(只显示相关的代码,其它代码都没有错,查询的内容不在同一张表)
--------------------------------------
/// <summary>
/// 求职者信息查询
/// </summary>
/// <param name="obj"></param>
/// <param name="odj"></param>
/// <returns>求职者信息</returns>
public DataSet getJskinfo(MST_Jskinfo obj, MST_Jskskill odj)
{
DataSet dsJskinfo = null;
//ACCESS实例作成
ComUser gJkinfo = new ComUser();
try
{
//DB连接
gJkinfo.dbAccess.ConnectionOpen();
// 事务处理开始
gJkinfo.dbAccess.TransactionBegin();
//业务处理
dsJskinfo = gJkinfo.SelectJskinfo(obj, odj);//每次从这儿就直接跳到catch
if (dsJskinfo == null)
{
throw new Exception("求职者信息查询失败");
}
//事务结束
gJkinfo.dbAccess.TransactionCommit();
}
catch (Exception e)
{
//Log处理
logger.Error(e);
//事务回滚
gJkinfo.dbAccess.TransactionRollBack();
dsJskinfo = null;
}
finally
{
if (!gJkinfo.dbAccess.ConnectionClose())
{
dsJskinfo = null;
}
}
return dsJskinfo;
}
--------------------------------------------
/// <summary>
/// 求职者信息查询
/// </summary>
/// <param name="obj"></param>
/// <param name="odj"></param>
/// <returns>求职者信息</returns>
public DataSet SelectJskinfo(MST_Jskinfo obj, MST_Jskskill odj)
{
//DBAcess部件调用
DataSet ds;
//sql语句选择函数定义成字符串便于引用和处理
string Jsk_SelctSql = JskSQL_SELECT(obj,odj);
if (obj == null || odj == null)
{
ds = null;
}
else
{
ds = this.dbAccess.dbSelect(Jsk_SelctSql, Jskinfo_MEAT.MST_NAME,null);//怀疑是这儿出错了
}
return ds;
}
-----------------------------------------------
/// <summary>
/// 根据条件选择合适求职者信息查询用SQL
/// </summary>
/// <autor>DXJ</autor>
/// <returns>合适的SQL语句</returns>
private string JskSQL_SELECT(MST_Jskinfo obj,MST_Jskskill odj)
{
string Jsk_info_SELECT = " Select distinct t1.JSK_NM,t1.JSK_Sex,t1.JSK_Bth ,"
+ " t1.JSK_School,t1.JSK_Exp,t2.Jsk_GD,t1.JSK_PosT,t1.JSK_State,t1.JSK_Op "
+ " From MST_Jskinfo t1 inner join MST_Jskskill t2 "
+ " On t1.JSK_ID=t2.JSK_ID inner join "
+ " MST_Jskexp t3 "
+ " On t2.JSK_ID=t3.JSK_ID "
+ " Where "
+ " JSK_State is not null ";
//没有检索条件用SQL
if (obj == null && odj == null)
{
return Jsk_info_SELECT;
}
//有检索条件用SQL
else
{ //求职方向不为空用SQL
if(obj.JSK_PosT!=null && !obj.JSK_PosT.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskinfo.JSK_PosT = '" + obj.JSK_PosT + "'";
}
//工作经验不为空用SQL
if(obj.JSK_Exp!=null && !obj.JSK_Exp.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskinfo.JSK_Exp = '" + obj.JSK_Exp + "'";
}
//语种不为空用SQL
if(odj.Small_NM!=null && !odj.Small_NM.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskskill.Small_NM ='" + odj.Small_NM + "'";
}
//语言等级不为空用SQL
if (odj.Jsk_GD != null && !odj.Jsk_GD.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskskill.Jsk_GD ='" + odj.Jsk_GD + "'";
}
//技术种类不为空用SQL
if(odj.Big_NM != null && !odj.Big_NM.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskskill.Big_NM ='" + odj.Big_NM + "'";
}
//技术名称不为空用SQL
if(odj.Small_NM !=null && !odj.Small_NM.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskskill.Small_NM ='" + odj.Small_NM + "'";
}
//期望工作地点不为空用SQL
if(obj.JSK_Place!=null && !obj.JSK_Place.Equals(""))
{
Jsk_info_SELECT = Jsk_info_SELECT + "And MST_Jskinfo.JSK_Place ='" + obj.JSK_Place + "'";
}
return Jsk_info_SELECT;
}
}
------------------------------------------------------
/// <summary>
/// 根据输入的查询SQL语句,SQL参数,表名从DB中检索数据,存入DataSet中
/// </summary>
/// <param name="sSelectSql">SQL语句</param>
/// <param name="sTableName">表名</param>
/// <param name="sqlpArray">SQL参数</param>
/// <returns>返回值DataSet</returns>
public DataSet dbSelect(string sSelectSql, string sTableName, SqlParameter[] sqlpArray)
{
logger.Info("SQL文" + sSelectSql + "\n");
if (sSelectSql == null)
{
return null;
}
if (sSelectSql.Length == 0)
{
return null;
}
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.Connection = conn;
if (tran != null)
{
sqlCmd.Transaction = tran;
}
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
sqlCmd.CommandText = sSelectSql;
da.SelectCommand = sqlCmd;
if (sqlpArray != null)
{
foreach (SqlParameter sqlp in sqlpArray)
{
if (sqlp != null)
{
da.SelectCommand.Parameters.Add(sqlp);
}
}
}
da.Fill(ds, sTableName);
return ds;
}