日期:2014-05-17  浏览次数:20796 次

怎么去除多表查询情况下的重复的老师信息的出现
try
  {
  int t = SecurityHelper.SafeRequestInt("T", 0);
  TableSelector xTableSelector = new TableSelector();
  CourseDal dal = new CourseDal();
  dal.SetCommand(TTlion.DataProvider.Common.CommandAction.Select);
  string tables = "Qz_Course c Inner Join Qz_User u on c.TeacherId=u.Id";
  string fields = " c.TeacherId,U.Name,U.EName,U.UserName,Time";
  int pageIndex = TTlion.Toolkit.SecurityHelper.SafeRequestInt("page", 1);
  string sWhere = "1=1 and StudentId={0} ";
  sWhere = string.Format(sWhere, CurrentUser.UserId);

  int totalCount = 0;
  using (DataSet source = dal.GetRecordFromPage(tables, fields, "c.TeacherId", sWhere, "c.TeacherId asc", 2, Pager.PageSize, pageIndex, out totalCount))
  {
  if (totalCount > 0)
  {
  if (totalCount > 0)
  {
  this.rptList.DataSource = source.Tables[0];
  this.rptList.DataBind();
  Pager.RecordCount = totalCount;
  }
  }

  }

  }
  catch
  {
  }

------解决方案--------------------
这个要从SQL语句着手,通过group by

或者

对数据集进行Filter过滤,将重复的去掉后,然后绑定到Repeater控件中


------解决方案--------------------
楼上说的,是可以的,group by来分组,去掉重复的,复杂的SQL文,可以通过,写储存过程来控制,在通过程序调用它。
------解决方案--------------------
通过SQL查询过滤,或使用LINQ的distinct过滤