[英]How to insert a datatable into SQL Server database using Uipath database activitvities?
I have a datatable DT
with 25 columns. 我有25列的数据表DT
。 I want to insert that data from DT
into a SQL Server table SQDT
with the same columns. 我想将该数据从DT
插入具有相同列的SQL Server表SQDT
。 I'm using an INSERT
query for now. 我现在正在使用INSERT
查询。
Is there a better way to approach this problem instead of using INSERT
on each record? 有没有比在每个记录上使用INSERT
更好的方法来解决此问题? Can I bulk insert into the database using a stored procedure or some other efficient way? 我可以使用存储过程或其他有效方式将数据批量插入数据库吗? It takes a lot of time to insert as DT
has 130000 tuples. 由于DT
具有130000个元组,因此插入时间很长。
Yes, there is a better way. 是的,有更好的方法。 You need to create Type in SQL server with the same definition as your Datatable. 您需要在SQL Server中使用与数据表相同的定义创建Type。
Here you can User-Defined TableType
在这里您可以User-Defined TableType
CREATE TYPE [dbo].[MyTable] AS TABLE(
[Id] int NOT NULL,
)
Define Parameter in SP 在SP中定义参数
CREATE PROCEDURE [dbo].[InsertTable]
@myTable MyTable readonly
AS
BEGIN
insert into [dbo].Records select * from @myTable
END
and send your DataTable
as a parameter 并将您的DataTable
作为参数发送
You can use SqlBulkCopy in-build for C#. 您可以将SqlBulkCopy内置用于C#。 SqlBulk Copy can be used for bulk inserts with batches which worked efficiently for me https://programmingwithmosh.com/net/using-sqlbulkcopy-for-fast-inserts/ SqlBulk Copy可用于批量插入的批量插入,这些批量插入对我有效:https: //programmingwithmosh.com/net/using-sqlbulkcopy-for-fast-inserts/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.