主题:如何杂VB.NET中比较数据库中两表的数据
小菜遇到一难题 请各位高手帮助:不胜感激!!!!!
先谢了!
现数据库中有A.B两表(两表列数一样,字段类型一样),如何在A表中选出一行数据与B表中数据比较,若找到相同的就从A表中再取一条记录与B表比较,直到A表的数据都取完.若在B表中找不到每列都相同的就返回信息,提示哪一列出错!
代码如下:
wxcheck 为A表 wxshch为B表
Dim jhh, khmc, khbh, daima, zhishu, yuan, sehao, ma, num As String为定义的表字段.
Dim dv1 As New DataView
Dim cust1 As New SqlClient.SqlDataAdapter
str1 = "select * from wxshch where checkid=0"
sql.Connection = con
sql.CommandText = str1
cust1.SelectCommand = sql
cust1.Fill(das, "wxshch")
Dim cust2 As New SqlClient.SqlDataAdapter
str2 = "select * from wxcheck"
sql.Connection = con
sql.CommandText = str2
cust2.SelectCommand = sql
cust2.Fill(das, "wxcheck")
dv1 = das.Tables("wxcheck").DefaultView
Dim jhh, khmc, khbh, daima, zhishu, yuan, sehao, ma, num As String
For i = 0 To das.Tables("wxcheck").Rows.Count - 1
jhh = LTrim(Trim(dv1(i).Item(1).ToString))
khmc = LTrim(Trim(dv1(i).Item(2).ToString))
khbh = LTrim(Trim(dv1(i).Item(3).ToString))
daima = LTrim(Trim(dv1(i).Item(4).ToString))
zhishu = LTrim(Trim(dv1(i).Item(5).ToString))
yuan = LTrim(Trim(dv1(i).Item(6).ToString))
sehao = LTrim(Trim(dv1(i).Item(7).ToString))
ma = LTrim(Trim(dv1(i).Item(8).ToString))
num = LTrim(Trim(dv1(i).Item(9).ToString))
MessageBox.Show(jhh)
For k = 0 To das.Tables("wxshch").Rows.Count - 1
Next
先谢了!
现数据库中有A.B两表(两表列数一样,字段类型一样),如何在A表中选出一行数据与B表中数据比较,若找到相同的就从A表中再取一条记录与B表比较,直到A表的数据都取完.若在B表中找不到每列都相同的就返回信息,提示哪一列出错!
代码如下:
wxcheck 为A表 wxshch为B表
Dim jhh, khmc, khbh, daima, zhishu, yuan, sehao, ma, num As String为定义的表字段.
Dim dv1 As New DataView
Dim cust1 As New SqlClient.SqlDataAdapter
str1 = "select * from wxshch where checkid=0"
sql.Connection = con
sql.CommandText = str1
cust1.SelectCommand = sql
cust1.Fill(das, "wxshch")
Dim cust2 As New SqlClient.SqlDataAdapter
str2 = "select * from wxcheck"
sql.Connection = con
sql.CommandText = str2
cust2.SelectCommand = sql
cust2.Fill(das, "wxcheck")
dv1 = das.Tables("wxcheck").DefaultView
Dim jhh, khmc, khbh, daima, zhishu, yuan, sehao, ma, num As String
For i = 0 To das.Tables("wxcheck").Rows.Count - 1
jhh = LTrim(Trim(dv1(i).Item(1).ToString))
khmc = LTrim(Trim(dv1(i).Item(2).ToString))
khbh = LTrim(Trim(dv1(i).Item(3).ToString))
daima = LTrim(Trim(dv1(i).Item(4).ToString))
zhishu = LTrim(Trim(dv1(i).Item(5).ToString))
yuan = LTrim(Trim(dv1(i).Item(6).ToString))
sehao = LTrim(Trim(dv1(i).Item(7).ToString))
ma = LTrim(Trim(dv1(i).Item(8).ToString))
num = LTrim(Trim(dv1(i).Item(9).ToString))
MessageBox.Show(jhh)
For k = 0 To das.Tables("wxshch").Rows.Count - 1
Next