# Error with DATABASE insert Activity

**URL:** <https://forum.uipath.com/t/error-with-database-insert-activity/226522>\
**Category:** Help\
**Tags:** database, activities\
**Created:** [May 27, 2020, 3:23pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522 "2020-05-27T15:23:39Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 27, 2020, 3:23pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/1 "2020-05-27T15:23:39Z")

</div>

I am facing an errror while inserting datatable into Datatbase due to the spaces in the column names. Is there any way of doing this without removing the spaces in column names and without loop as well?

---

<div class="post-metadata">

**Author:** ![unknownay](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/unknownay/32/213245_2.png) [@unknownay](https://forum.uipath.com/u/unknownay)\
**Post date:** [May 27, 2020, 7:34pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/2 "2020-05-27T19:34:55Z")

</div>

Hi @Sugumar8785

You need to remove the spaces in column names because databases are not going to accept column names with space. If you try to create a Table in MSSQL you can observe that a square bracket will be kept by designer itself.

If you keep square bracket it might accept [Column Name]

Regards  
Roshan

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 2:38pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/3 "2020-05-28T14:38:30Z")

</div>

@lakshman @ppr @ovi @loginerror

While using Insert activity to insert datatable into database, there is an issue as there are spaces in the column name. I would like to have the column names as it is and I dont want to use loop to insert row by row as I am having huge volume of data.

Is there any alternative way of doing this please.

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 4:11pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/4 "2020-05-28T16:11:02Z")

</div>

@Palaniyappan @supermanPunch @Lahiru.Fernando @sandeep13

Please help me if you have any idea.

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [May 28, 2020, 4:26pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/5 "2020-05-28T16:26:11Z")

</div>

Hello @Sugumar8785

It is not a good practice to have spaces in column names. So always try to make it a practice to have column names in ColumnName format. However, if you need to have those spaces and unable to remove them now, for the column name, you might need to use the square bracket to surround the column name.

For example  
Insert into dbo.TableName ([Column name 1], [Column name 2]) values (1,“Test value”)

Try this and let us know whether it works 🙂

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 4:31pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/6 "2020-05-28T16:31:03Z")

</div>

Thanks. I understand that best practice. But there is a requirement where I had to do it as legacy system demands it.

I have a huge data. If I use the query in loop , it will take forever. Is there any alternate ?

Does **bulkCopy.WriteToServer(DataTableName);** works in the same way of Insert activity?

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [May 28, 2020, 4:36pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/7 "2020-05-28T16:36:07Z")

</div>

@Sugumar8785 - You can use the “Insert” activity that you find under UiPath.Database.Activities to directly insert a datatable without looping and inserting one row at a time. Have you tried this activity?

 ![image](https://global.discourse-cdn.com/uipath/original/3X/a/a/aab74e966c41b58d3cf9bf20253ce3808c589243.png)

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 4:39pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/8 "2020-05-28T16:39:41Z")

</div>

yes, I having issue in that activity because of the spaces in the column names. ☹

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 4:42pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/9 "2020-05-28T16:42:25Z")

</div>

@balupad14 please let me know if you can here.

---

<div class="post-metadata">

**Author:** ![sandeep13](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sandeep13/32/79017_2.png) [@sandeep13](https://forum.uipath.com/u/sandeep13)\
**Post date:** [May 28, 2020, 4:45pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/10 "2020-05-28T16:45:16Z")

</div>

@Sugumar8785 are you sure reason could be Space in the Column?

Datatable column description must match with column of Database

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 4:50pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/11 "2020-05-28T16:50:56Z")

</div>

Yeah, I am sure. I verified changing the column names (as per best practices) in both DB and Datatable. It worked that time.

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [May 28, 2020, 4:51pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/12 "2020-05-28T16:51:07Z")

</div>

@Sugumar8785 What is the error that you get when you try to insert the data using that activity? Is the error saying that its because of the column name contains spaces?

I think bulk copy option that you mentioned, should do the job… But you will have to get some additional steps added to the workflow to get it working as shown in those example codes in the microsoft site…

> **[SqlBulkCopy.WriteToServer Method (System.Data.SqlClient)](https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlbulkcopy.writetoserver?view=dotnet-plat-ext-3.1)**
>
> Copies all rows from a data source to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

---

<div class="post-metadata">

**Author:** ![Sugumar8785](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sugumar8785/32/136511_2.png) [@Sugumar8785](https://forum.uipath.com/u/Sugumar8785)\
**Post date:** [May 28, 2020, 4:59pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/13 "2020-05-28T16:59:54Z")

</div>

@Lahiru.Fernando While I am using Insert activity, it is taking the words ‘TABLE’, ‘ALL’, ‘WITH’ as keywords and getting an error.

I tried removing the spaces between the column names in DB and DT and executed. It worked that time.

---

<div class="post-metadata">

**Author:** ![sandeep13](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sandeep13/32/79017_2.png) [@sandeep13](https://forum.uipath.com/u/sandeep13)\
**Post date:** [May 28, 2020, 5:14pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/14 "2020-05-28T17:14:29Z")

</div>

@Sugumar8785  
you can do one thing …create store Proc for that and use Execute Non Query activity

CREATE PROCEDURE [dbo].[Insert\_Customers]  
@tblCustomers CustomerType READONLY  
AS  
BEGIN  
SET NOCOUNT ON;

```
  INSERT INTO Customers(CustomerId, Name, Country)
  SELECT Id, Name, Country FROM @tblCustomers

```

END

---

<div class="post-metadata">

**Author:** ![Lahiru.Fernando](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lahiru.fernando/32/523857_2.png) [@Lahiru.Fernando](https://forum.uipath.com/u/Lahiru.Fernando)\
**Post date:** [May 28, 2020, 5:21pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/15 "2020-05-28T17:21:09Z")

</div>

The approach @sandeep13 gave is really good… Try that and see… it should work for you…

---

<div class="post-metadata">

**Author:** ![AVipani](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/avipani/32/176682_2.png) [@AVipani](https://forum.uipath.com/u/AVipani)\
**Post date:** [August 6, 2021, 6:41pm UTC](https://forum.uipath.com/t/error-with-database-insert-activity/226522/16 "2021-08-06T18:41:23Z")

</div>

Hi, @Lahiru.Fernando

Has anyone found a solution to this.

Am having a Merge query to be passed in Execute non-query and the column names have spaces in them.

Also, Uipath does not support multi line query ?

Appreciate if someone can post a solution here.
