本文介绍了循环两个数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从查询中得到了dt1
cmd.CommandText =SELECT DISTINCT AdminNo,ModuleCode FROM(SEGDATA)ORDER BY AdminNo ASC,ModuleCode ASC
Dim dt1 As New DataTable
dt1.Load(cmd.ExecuteReader)
DataGridView1.AutoGenerateColumns = True
DataGridView1.DataSource = dt1
另一个查询dt2
cmd.CommandText =SELECT DISTINCT PaperNo,ModuleCode1,ModuleCode2,ModuleCode3,ModuleCode4,ModuleCode5 ,ModuleCode6,ModuleCode7,ModuleCode8,ModuleCode9 FROM(PapersList)ORDER BY PaperNo ASC
Dim dt2 As New DataTable
dt2.Load(cmd.ExecuteReader)
DataGridView2.AutoGenerateColumns = True
DataGridView2.DataSource = dt2
dt1如下:
AdminNo ModuleCode
111411H EG1001
111411H Eg1003
111380Y EG2011
dt2看起来像:
PaperNo Module1 Module2 Module3 ....
1 EG1001
2 EG1003 EG1001
3 EG2011
我如何循环这两张表来获得:
AdminNo PaperNo
111411H 1
111411H 2
111380Y 3
任何人都帮我编码,谢谢!
解决方案
i have dt1 from a query
cmd.CommandText = "SELECT DISTINCT AdminNo, ModuleCode FROM(SEGDATA)ORDER BY AdminNo ASC, ModuleCode ASC" Dim dt1 As New DataTable dt1.Load(cmd.ExecuteReader) DataGridView1.AutoGenerateColumns = True DataGridView1.DataSource = dt1
another query dt2
cmd.CommandText = "SELECT DISTINCT PaperNo,ModuleCode1,ModuleCode2,ModuleCode3, ModuleCode4, ModuleCode5, ModuleCode6, ModuleCode7, ModuleCode8, ModuleCode9 FROM(PapersList)ORDER BY PaperNo ASC" Dim dt2 As New DataTable dt2.Load(cmd.ExecuteReader) DataGridView2.AutoGenerateColumns = True DataGridView2.DataSource = dt2
dt1 looks like:
AdminNo ModuleCode 111411H EG1001 111411H Eg1003 111380Y EG2011
dt2 looks like:
PaperNo Module1 Module2 Module3 .... 1 EG1001 2 EG1003 EG1001 3 EG2011
How do i loop these 2 tables to get:
AdminNo PaperNo
111411H 1
111411H 2
111380Y 3
Anybody help me with the codes, thanks!
解决方案
这篇关于循环两个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!