本文介绍了检查多列数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dt1看起来像:
dt1 looks like:
AdminNo ModuleCode
111411H EG1001
111411H Eg1003
111380Y EG2011
dt2看起来像:
dt2 looks like:
PaperNo Module1 Module2 Module3 ....
1 EG1001
2 EG1003 EG1001
3 EG2011
i想要检查dt1中每个模块对dt2的每一行和每一行。
例如:EG1001出现在col1,col2,col3 ......
i的代码如下:
i want to check for each modulecode in dt1 to each row and column of dt2.
Example: is EG1001 appearing in col1, col2, col3 ...
i have codes as follows:
Dim dt3 As New DataTable
dt3.Columns.Add("AdminNo", GetType(String))
dt3.Columns.Add("PaperNo", GetType(Integer))
Dim curmodule As String = String.Empty
For Each dr2 As DataRow In dt2.Rows
curmodule = dr2("ModuleCode1").ToString
For Each dr1 As DataRow In dt1.Rows
If curmodule = dr1("ModuleCode").ToString Then
Dim dt3row As DataRow
dt3row = dt3.NewRow
dt3row("AdminNo") = dr1("AdminNo")
dt3row("PaperNo") = dr2("PaperNo")
dt3.Rows.Add(dt3row)
Me.DataGridView3.DataSource = dt3
它只对dt2中的一列进行检查。
任何人都帮帮我,谢谢!
its only checking against one column in dt2.
anyone help me out, thanks!
推荐答案
For Each dr1 As DataRow In dt1.Rows
var module=dr1("ModuleCode1").ToString
For Each dr2 As DataRow In dt2.Rows</pre>
如果curmodule = dr1(ModuleCode)。ToString那么
//做逻辑
希望这有帮助
If curmodule = dr1("ModuleCode").ToString Then
//do the logic
Hope this helps
Dim dt3 As New DataTable
dt3.Columns.Add("AdminNo", GetType(String)) '/*Add column AdminNo
dt3.Columns.Add("PaperNo", GetType(Integer))
Dim curmodule As String = String.Empty
For Each dr1 As DataRow In dt1.Rows
curmodule = dr1("ModuleCode").ToString
For Each dr2 As DataRow In dt2.Rows
Dim found As Boolean
found = False
For i = 0 To dt2.Columns.Count - 1
If curmodule = dr2(i).ToString Then
found = True
Dim dr3 As DataRow
dr3 = dt3.NewRow
dr3("AdminNo") = dr1("AdminNo")
dr3("PaperNo") = dr2("PaperNo")
dt3.Rows.Add(dr3)
DataGridView3.AutoGenerateColumns = True
Me.DataGridView3.DataSource = dt3
End If
Next
Next
Next
这篇关于检查多列数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!