载数据库表中,用select distinct [列名]……很容易实现返回独有的列值,那么在内存中的DataTable对像如何实现类似的功能?
解决方案 »
- 急求!!!
- C# 做服务端该怎么做好啊
- 怎样取得input里面的Value值?
- DataGrid自动创建列的问题!
- ASPxGridView+模板列,能不能像在Excel中那样操作,如果可以的话,要如何代码??急!!!
- 在某行处于编辑模式时怎么绑定数据到DataGrid的模板列中的DropDownList控件上??
- 无法将类型“int”隐式转换为“System.Management.AuthenticationLevel”。存在一个显式转换(是否缺少强制转换?)
- 如何将查到的内容ADD到Combox的下拉列表中?比较傻的问题,请大家帮忙!在线等!
- 我想把datagrid的一列固定长度,改怎么做呢?请教高手。
- 高分请教:如何用c#将EXCEL数据加载到ORACLE数据库中?
- 各位,Remoting服务如何停止
- 求SourceSafe8.0,急等!!高分!!
public DataRow[] GetDistinctRow(DataTable aTable,string[] columnList)
{
DataRow[] rowList = null;
if ( aTable.Count <= 0)
return rowList;
string strOrginSort = aTable.Sort ;
string strSort = "";
for (int i = 0 ; i < columnList.Length ; i++)
strSort += " ," + columnList[i];
if ( strSort.Trim().Length > 0)
strSort = strSort.Remove(0,2);
aTable.Sort = strSort;
string strColValue = "";
string strFlag = "-1";
DataRow aRow = aTable[0].Row ;
for ( int iCol = 0 ; iCol < columnList.Length ; iCol++)
strColValue += aRow[columnList[iCol]] .ToString().Trim();
if (strFlag == strColValue)
strFlag = "-2";
ArrayList array = new ArrayList();
for(int iRow = 0;iRow< this.Count;iRow++)
{
aRow = aTable[iRow].Row;
strColValue = "";
for ( int iCol = 0 ; iCol < columnList.Length ; iCol++)
strColValue += aRow[columnList[iCol]].ToString().Trim();
if ( strFlag != strColValue)
{
array.Add(aRow);
strFlag = strColValue ;
}
}
rowList = new DataRow[array.Count];
for ( int iRow = 0 ; iRow < rowList.Length ; iRow++)
rowList[iRow] = (DataRow)array[iRow];
return rowList;
}
for(int j=0; j< DataTable.Columns.Count;j++)
{
string Value = DataTable[i][j]; //Value表示当前矩阵中一个元素值.
}
我在1.0的时候就在寻找,最后还是用自己写的方法 :)