如何筛选重复的数据
取得数据集结果如下
id name name1
1 a b
2 a b
3 c c
4 d d
5 d d
6 e e
需要返回的结果是
name name1
a b
c c
d d
e e
谢谢了
7 个解决方案
#1
select distinct name,name1 from 表
#2
没看清题目,算我没说
#3
提供思路
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
#4
提供思路
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
#5
http://blog.aspcool.com/jiezhi/archive/2005/01/05/1637.html
#6
将数据导入ArrayList再筛选重复的数据后转入DataTable中!
#7
list2是mobile的控件,你换成asp.net控件吧。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim table As DataTable = create_table()
Dim i, j As Integer
For i = 0 To table.Rows.Count - 1
For j = i + 1 To table.Rows.Count - 1
If table.Rows(i)("name").ToString = table.Rows(j)("name").ToString Then
table.Rows(j)("name") = System.DBNull.Value
End If
Next j
Next i
Dim dv As DataView = table.DefaultView
List2.DataSource = dv
List2.DataBind()
End If
End Sub
Function create_table()
Dim mydatatable As DataTable = New DataTable("mydatatable")
Dim mydatacolumn As DataColumn
Dim mydatarow As DataRow
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name"
mydatatable.Columns.Add(mydatacolumn)
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name1"
mydatatable.Columns.Add(mydatacolumn)
'以上创建表结构
'行一
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行二
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行三
mydatarow = mydatatable.NewRow
mydatarow("name") = "c"
mydatarow("name1") = "c"
mydatatable.Rows.Add(mydatarow)
'行四
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行五
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行六
mydatarow = mydatatable.NewRow
mydatarow("name") = "e"
mydatarow("name1") = "e"
mydatatable.Rows.Add(mydatarow)
Return mydatatable
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim table As DataTable = create_table()
Dim i, j As Integer
For i = 0 To table.Rows.Count - 1
For j = i + 1 To table.Rows.Count - 1
If table.Rows(i)("name").ToString = table.Rows(j)("name").ToString Then
table.Rows(j)("name") = System.DBNull.Value
End If
Next j
Next i
Dim dv As DataView = table.DefaultView
List2.DataSource = dv
List2.DataBind()
End If
End Sub
Function create_table()
Dim mydatatable As DataTable = New DataTable("mydatatable")
Dim mydatacolumn As DataColumn
Dim mydatarow As DataRow
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name"
mydatatable.Columns.Add(mydatacolumn)
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name1"
mydatatable.Columns.Add(mydatacolumn)
'以上创建表结构
'行一
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行二
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行三
mydatarow = mydatatable.NewRow
mydatarow("name") = "c"
mydatarow("name1") = "c"
mydatatable.Rows.Add(mydatarow)
'行四
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行五
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行六
mydatarow = mydatatable.NewRow
mydatarow("name") = "e"
mydatarow("name1") = "e"
mydatatable.Rows.Add(mydatarow)
Return mydatatable
End Function
#1
select distinct name,name1 from 表
#2
没看清题目,算我没说
#3
提供思路
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
#4
提供思路
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
可以对datatable进行操作
…dt
DataTable dtTmp = dt.Clone();
IEnumerator myEnumerator = dtTmp.Rows.GetEnumerator();
while(myEnumerator.MoveNext())
{
……
}
最后再组合成新DataTable
#5
http://blog.aspcool.com/jiezhi/archive/2005/01/05/1637.html
#6
将数据导入ArrayList再筛选重复的数据后转入DataTable中!
#7
list2是mobile的控件,你换成asp.net控件吧。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim table As DataTable = create_table()
Dim i, j As Integer
For i = 0 To table.Rows.Count - 1
For j = i + 1 To table.Rows.Count - 1
If table.Rows(i)("name").ToString = table.Rows(j)("name").ToString Then
table.Rows(j)("name") = System.DBNull.Value
End If
Next j
Next i
Dim dv As DataView = table.DefaultView
List2.DataSource = dv
List2.DataBind()
End If
End Sub
Function create_table()
Dim mydatatable As DataTable = New DataTable("mydatatable")
Dim mydatacolumn As DataColumn
Dim mydatarow As DataRow
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name"
mydatatable.Columns.Add(mydatacolumn)
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name1"
mydatatable.Columns.Add(mydatacolumn)
'以上创建表结构
'行一
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行二
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行三
mydatarow = mydatatable.NewRow
mydatarow("name") = "c"
mydatarow("name1") = "c"
mydatatable.Rows.Add(mydatarow)
'行四
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行五
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行六
mydatarow = mydatatable.NewRow
mydatarow("name") = "e"
mydatarow("name1") = "e"
mydatatable.Rows.Add(mydatarow)
Return mydatatable
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim table As DataTable = create_table()
Dim i, j As Integer
For i = 0 To table.Rows.Count - 1
For j = i + 1 To table.Rows.Count - 1
If table.Rows(i)("name").ToString = table.Rows(j)("name").ToString Then
table.Rows(j)("name") = System.DBNull.Value
End If
Next j
Next i
Dim dv As DataView = table.DefaultView
List2.DataSource = dv
List2.DataBind()
End If
End Sub
Function create_table()
Dim mydatatable As DataTable = New DataTable("mydatatable")
Dim mydatacolumn As DataColumn
Dim mydatarow As DataRow
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name"
mydatatable.Columns.Add(mydatacolumn)
'添加一列
mydatacolumn = New DataColumn
mydatacolumn.DataType = System.Type.GetType("System.String")
mydatacolumn.ColumnName = "name1"
mydatatable.Columns.Add(mydatacolumn)
'以上创建表结构
'行一
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行二
mydatarow = mydatatable.NewRow
mydatarow("name") = "a"
mydatarow("name1") = "b"
mydatatable.Rows.Add(mydatarow)
'行三
mydatarow = mydatatable.NewRow
mydatarow("name") = "c"
mydatarow("name1") = "c"
mydatatable.Rows.Add(mydatarow)
'行四
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行五
mydatarow = mydatatable.NewRow
mydatarow("name") = "d"
mydatarow("name1") = "d"
mydatatable.Rows.Add(mydatarow)
'行六
mydatarow = mydatatable.NewRow
mydatarow("name") = "e"
mydatarow("name1") = "e"
mydatatable.Rows.Add(mydatarow)
Return mydatatable
End Function