好贷网好贷款

取distinct数据的方法

发布时间:2016-12-4 22:24:41 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"取distinct数据的方法",主要涉及到取distinct数据的方法方面的内容,对于取distinct数据的方法感兴趣的同学可以参考一下。

private static bool ColumnEqual(object A, object B)  {   // Compares two values to see if they are equal. Also compares DBNULL.Value.   // Note: If your DataTable contains object fields, then you must extend this   // function to handle them in a meaningful way if you intend to group on them.    if (A == DBNull.Value && B == DBNull.Value) // both are DBNull.Value    return true;   if (A == DBNull.Value || B == DBNull.Value) // only one is DBNull.Value    return false;   return (A.Equals(B)); // value type standard comparison  }  private void AddCombox2()  {   DataTable dt = new DataTable(StuDS.sldrpurplan.TableName);   dt.Columns.Add("MateSpec", StuDS.sldrpurplan.Columns["MateSpec"].DataType);   object LastValue = null;   foreach (DataRow dr in StuDS.sldrpurplan.Select("", "MateSpec"))   {    if (LastValue == null || !(ColumnEqual(LastValue, dr["MateSpec"])))    {     LastValue = dr["MateSpec"];     dt.Rows.Add(new object[] { LastValue });    }   }   foreach(DataRow dr in dt.Rows)      {    comboBox2.Items.Add(dr["MateSpec"].ToString());   }  }==========================================//原码这里有一个取distinct数据的方法. static DataTable SelectDistinct(string ReturnTableName, DataTable SourceTable, string ReturnFieldName, string AdditionalFilterExpression){DataTable dt = new DataTable(ReturnTableName);dt.Columns.Add(ReturnFieldName, SourceTable.Columns[ReturnFieldName].DataType);object LastValue = null;foreach (DataRow dr in SourceTable.Select("", ReturnFieldName)){if (LastValue == null || !(ColumnEqual(LastValue, dr[ReturnFieldName]))){LastValue = dr[ReturnFieldName];dt.Rows.Add(new object[] { LastValue });}}if (ds != null)ds.Tables.Add(dt);return dt;} static bool ColumnEqual(object A, object B){// Compares two values to see if they are equal. Also compares DBNULL.Value.// Note: If your DataTable contains object fields, then you must extend this// function to handle them in a meaningful way if you intend to group on them. if (A == DBNull.Value && B == DBNull.Value) // both are DBNull.Valuereturn true;if (A == DBNull.Value || B == DBNull.Value) // only one is DBNull.Valuereturn false;return (A.Equals(B)); // value type standard comparison} 

上一篇:错误15023:当前数据库中已存在用户或角色
下一篇:Nash演讲稿中文版

相关文章

相关评论