从Excel存储中获取数据到不同表中的数据库 [英] Get Data from Excel store to db in different tables

查看:99
本文介绍了从Excel存储中获取数据到不同表中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在excel中有一些数据说:

1 aa bb cc

2 dd ef ff



前两列必须存储到数据库(MS Sql)中的主表,另外两列存储到使用外键关联的子表。我们如何将这些数据附加到mastertable和子表。如果主表已包含数据,则它将自动递增以追加第一列。例如

我有数据的主表

1 xx

.. ..

.. ..

100 pp

因此我想将next-1 aa存储在此下方,因此1将不会输入1而是101,它将是

101 aa

和儿童餐桌

101 ee ff

如何实现这一目标,单独的数据,放在两个不同的表格中维护外键关系?

解决方案

请使用以下步骤。



1.阅读上传的内容excel文件到数据表。

2.运行数据表的循环。

3.使用主表的列构建一个insert语句并将其存储在变量中。

4.使用子表的列构建一个insert语句并将其存储在变量中。

5.在数据表循环后执行上述查询。

Im having some data in excel say:
1 aa bb cc
2 dd ee ff

The first two columns have to be stored to master table in database(MS Sql) and the other two , to a child table which is related using foreign key. How can we append this data to mastertable and child table. If the master table already contains data it will append the first column since its auto incremented. eg
I have master table with data
1 xx
.. ..
.. ..
100 pp
so i want to store next- 1 aa below this, so the 1 will not be entered as 1 but 101, it will be
101 aa
and in child table
101 ee ff
How can I achieve this, separate data, put in two different tables and maintain the foreign key relation?

解决方案

Please use the following steps.

1. Read the uploaded excel file to the datatable.
2. Run the loop for the datatable.
3. Build an insert statement with the columns of the master table and store it in a variable.
4. Build an insert statement with the columns of the child table and store it in a variable.
5. Execute the above queries after the datatable loop.


这篇关于从Excel存储中获取数据到不同表中的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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