dataview 可以将一个dt重新排序 或是筛选 可是如果要实现distinct 得话好像没有直接得方法,要实现discinct和count的话 研究了一下可以按下面的方法来做 可能效率低了点 可是暂时没有更好的方法了 呵呵
SqlConnection con = new SqlConnection(Constr);
SqlDataAdapter da = new SqlDataAdapter("select * from test",con);
DataTable dt = new DataTable();
da.Fill(dt);
DataView dv = new DataView(dt);
dv.Sort = "name";
dt = dv.ToTable();
DataTable tb = new DataTable();
DataColumn col1 = new DataColumn("name");
DataColumn col2 = new DataColumn("count");
tb.Columns.Add(col1);
tb.Columns.Add(col2);
DistinctDistinct
CountCount
GvData.DataSource = tb;
GvData.DataBind();
SqlDataAdapter da = new SqlDataAdapter("select * from test",con);
DataTable dt = new DataTable();
da.Fill(dt);
DataView dv = new DataView(dt);
dv.Sort = "name";
dt = dv.ToTable();
DataTable tb = new DataTable();
DataColumn col1 = new DataColumn("name");
DataColumn col2 = new DataColumn("count");
tb.Columns.Add(col1);
tb.Columns.Add(col2);
DistinctDistinct
CountCount
GvData.DataSource = tb;
GvData.DataBind();