更新表与相同的项目 [英] update table with the same items

查看:42
本文介绍了更新表与相同的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两张A和B牌桌。

表A

HoleNo Depth_from Depth_to

A1 1 2

A1 3 4

A1 5 6



表B

HoleNo Depth_from Depth_to

A1

A1

A1



现在如何更新表B以使其看起来像表A

注意,不必对表A进行任何更改。

我试图将id'分配给表B,以便我根据表进行更新独特的ID',但由于我不对表AI进行任何更改,我觉得很难。



这是我的代码

我首先保存 全部 HoleNo 进入 B 来自 A 
sqlSTR = SELECT * FROM A
ExecuteSQLQuery(sqlSTR)' 调用函数执行查询
For Each row1 As DataRow in sqlDT.Rows

sqlSTR =INSERT INTO B(HoleNo)VALUES(' & row1(0)& '
ExecuteSQLQuerylocal(sqlSTR)'
调用 function to 执行查询

下一个

因此在插入所有 HoleNo 然后后我尝试 更新其余 字段 with 此代码

sqlSTR = SELECT * FROM一个
ExecuteSQLQuery(sqlSTR)' 调用函数来执行查询
For每行1作为DataRow在sqlDT.Rows

sqlSTR =UPDATE B SET Depth_from ='
&第(0)行 ' WHERE HoleNo =' &第(0)行 '
ExecuteSQLQuerylocal(sqlSTR)

Next

解决方案

从数据库中删除表B

然后从表A创建表B



使用Sql查询

  DROP   TABLE  B 
GO
SELECT * INTO B 来自 A
GO


I have two tables A and B shown.
Table A
HoleNo Depth_from Depth_to
A1 1 2
A1 3 4
A1 5 6

Table B
HoleNo Depth_from Depth_to
A1
A1
A1

Now How do I update table B so that it looks like table A
Note that no changes must be made to table A.
I have tried to assign id''s to table B so that I do the update based on the unique id''s, but since I am not to make any changes to table A I am finding it very difficult.

this is my code

I first save all HoleNo into B from A
sqlSTR = "SELECT * FROM A"
ExecuteSQLQuery(sqlSTR) 'call function to execute the query
For Each row1 As DataRow In sqlDT.Rows

sqlSTR = "INSERT INTO B (HoleNo) VALUES ('" & row1(0) & "')"
ExecuteSQLQuerylocal(sqlSTR) 'call function to execute the query

Next

So after inserting all HoleNo then I try to update the rest of the fields with this code

sqlSTR = "SELECT * FROM A"
ExecuteSQLQuery(sqlSTR) 'call function to execute the query
For Each row1 As DataRow In sqlDT.Rows

sqlSTR = "UPDATE B SET Depth_from ='" & row(0) & "' WHERE HoleNo ='" & row(0) & "'"
ExecuteSQLQuerylocal(sqlSTR)

Next

解决方案

Delete Table B from Database
then Create Table B from Table A

Use Sql Query

     DROP TABLE B
GO
     SELECT * INTO B From A
GO


这篇关于更新表与相同的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆