c#数据筛选

小菜鸟__菜鸟 2017-11-30 04:02:31
OA_Customers cus = new OA_Customers();
IList<OA_CustomersInfo> c= c.GetInfoByWhere("top 4", where,orderby , 0);
OA_ZDJL zdjl = new OA_ZDJL();
IList<OA_ZDJLInfo> z = zdjl.GetInfoByWhere("", "where Jssj>getdate()", orderby);


emmm OA_ZDJL中的XmId 与 OA_Customers中的Id有部分重合,我想根据OA_ZDJL中的XmId 筛选出OA_Customers的数据


this.rptTopList.DataSource = 得到的数据;
this.rptTopList.DataBind();
...全文
619 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
小菜鸟__菜鸟 2017-12-04
  • 打赏
  • 举报
回复
我知道怎么查询select,我就是不知道怎么利用这个查询结果,怎么把这些查询出来的数据一条条赋值给OA_Customers c = new OA_Customers();这个,我也知道可以用遍历,其实就是我不知道具体怎么个代码去写,原理是知道的,可能我才接触这个,都在一点点的摸索着,我试过很多,每次都是最后一步怎么都写不出,也是最重要的结果无法写出来,所以我就只能求助论坛了,然后目前我也没看到什么具体的
小菜鸟__菜鸟 2017-12-04
  • 打赏
  • 举报
回复
private string SqlGetInfoByWhere = "select <top> * from (select t1.*,isnull(t2.jyjg,'') as jyjg,isnull(t2.zzf,'') as zzf,isnull((select max(UserTypeID) from dbo.OA_memberXf where userid = t1.tgr and EndTime >= getdate() and CreateTime <= getdate()),1) as userType,(select Count(*) from OA_CustomerGz where cid = t1.id) as gzcount from OA_Customers as t1 left join dbo.OA_Companys as t2 on t1.companyid = t2.id) as t99 <where> <orderby>"; /// <summary> /// 按条件获取信息 /// </summary> /// <param name="top"></param> /// <param name="where"></param> /// <param name="orderby"></param> /// <returns></returns>public IList<OA_CustomersInfo> GetInfoByWhere(string top, string where, string orderby, int StrLength) { if (!string.IsNullOrEmpty(top)) SqlGetInfoByWhere = SqlGetInfoByWhere.Replace("<top>", top); else SqlGetInfoByWhere = SqlGetInfoByWhere.Replace("<top>", ""); if (!string.IsNullOrEmpty(where)) SqlGetInfoByWhere = SqlGetInfoByWhere.Replace("<where>", where); else SqlGetInfoByWhere = SqlGetInfoByWhere.Replace("<where>", ""); if (!string.IsNullOrEmpty(orderby)) SqlGetInfoByWhere = SqlGetInfoByWhere.Replace("<orderby>", orderby); else SqlGetInfoByWhere = SqlGetInfoByWhere.Replace("<orderby>", ""); IList<OA_CustomersInfo> mylist = new List<OA_CustomersInfo>();
小菜鸟__菜鸟 2017-12-04
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
对于内存中两个可枚举集合,可以使用 linq for object 来筛选出第三个集合,例如
from x in list1
where (from y in list2 where y.num==x.a+x.b*2 select y).Any()
select x;
当然这只是一个例子,启发你了解将复杂查询写成一个类似 sql 式的说明表达式的 linq 技术。
小菜鸟__菜鸟 2017-12-01
  • 打赏
  • 举报
回复
我从OA_ZDJL中获取XmId得到一个字符串怎么去匹配OA_Customers中的数据 for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { val += ds.Tables[0].Rows[i]["XmId"].ToString(); } val是获取到的字符串 我想着用foreach(char v in val)但没反应 IList<OA_CustomersInfo> zdList = c.GetInfoByWhere("top 2", "where id = " +val中的字符, orderby, 0); this.rptTopList.DataSource = zdList; this.rptTopList.DataBind(); 跪求大佬帮我看看,本人超级小白
小菜鸟__菜鸟 2017-12-01
  • 打赏
  • 举报
回复
private string SqlGetInfoByWhere = "select <top> * from (select t1.*,isnull(t2.jyjg,'') as jyjg,isnull(t2.zzf,'') as zzf,isnull((select max(UserTypeID) from dbo.OA_memberXf where userid = t1.tgr and EndTime >= getdate() and CreateTime <= getdate()),1) as userType,(select Count(*) from OA_CustomerGz where cid = t1.id) as gzcount from OA_Customers as t1 left join dbo.OA_Companys as t2 on t1.companyid = t2.id) as t99 <where> <orderby>"; IList<OA_CustomersInfo> GetInfoByWhere(string top, string where, string orderby, int StrLength) 这个有关联么
吉普赛的歌 2017-12-01
  • 打赏
  • 举报
回复
SELECT *
FROM   OA_Customers a
       JOIN OA_ZDJL b
            ON  a.id = b.XmId
WHERE  b.Jssj > GETDATE()
你把 GetInfoByWhere 这个方法的代码贴出来。
小菜鸟__菜鸟 2017-12-01
  • 打赏
  • 举报
回复
string val = "select * from OA_Customers join OA_ZDJL on OA_Customers.id = OA_ZDJL.XmId where (OA_ZDJL.Jssj>getdate()"; 这个val就是查到的结果,我想把他赋给下面的这个c但是我不知道怎么赋给他 OA_Customers c = new OA_Customers(); IList<OA_CustomersInfo> zdList = c.GetInfoByWhere("top 2",where, orderby, 0); this.rptTopList.DataSource = zdList; this.rptTopList.DataBind();
吉普赛的歌 2017-12-01
  • 打赏
  • 举报
回复
如果你的是从数据库里面查到的, 那就不如直接用 sql 语句直接写好, 传回结果就是
小菜鸟__菜鸟 2017-12-01
  • 打赏
  • 举报
回复
for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { val += ds.Tables[0].Rows[i]["XmId"].ToString(); } 怎么根据字符串去筛选
threenewbee 2017-11-30
  • 打赏
  • 举报
回复
GetInfoByWhere 这个方法内部怎么实现的,是否支持多个条件?用sql就简单了。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧