How to insert data into Database from using UiPath, getting error "Invalid Column Name"

Hi
I have a small problem.
After my process reads data from salesforce, I separate it and store it in some variables.
Now , I have to insert that data from variables into my database which is hosted locally.
I have connected to database and I am using Execute Non -Query activity, but getting error saying “Invalid Column Names”. I guess I am missing something so it is not able to insert.

Below is my Table structure in database.:
SELECT TOP (1000) [Name]
,[Country]
,[Address]
,[City]
,[State]
,[PostCode]
,[Email]
FROM [ANZ CMD Legal].[dbo].[ContactDetails]

Below is my query which I ma using in UiPath:

“INSERT Into [ANZ CMD Legal].[dbo].[ContactDetails] (Name, Country, Address, City, State, PostCode, Email) Values(Name, Country, Address, City, State, PostCode, Email)”

After running the code, I am getting the below error:

Can anyone please if I am missing anything or anything needs to be updated.

Thanks

your statement looks fine, can you confirm you are connected to the database correctly first?

Hi, yes I checked , the connection seems fine, i have used Connect command above my execute non-query, it does establish the connection as i have put one message box to see the same.
the values comes in message box, and but after that it says “invalid column name”
not sure why this happening.

any other info required , let me know

if these are your variables then the query should be
“INSERT Into [ANZ CMD Legal].[dbo].[ContactDetails] (Name, Country, Address, City, State, PostCode, Email) Values(’" + Name + “’, '” + Country + “’, '” + Address + “’, '” + City + “’, '” + State + “’, '” + PostCode + “’, '” + Email + "’)”

it says incorrect syntax:

what are variables here?

Are these the ones?

yes these are the variables, correct

If she is using variables with parameters, the statement is correct.

Does the Select query mentioned work??

yes I am using the values to be inserted into database as variables.
they are not being used as any parameters as of now.
Directly they are being used as variables and inserted into the above mentioned query

Then you will need amend your statement as @ashley11

You may need to replace some of the ’ in the statement as they look incorrect format as below.

"INSERT Into [ANZ CMD Legal].[dbo].[ContactDetails] (Name, Country, Address, City, State, PostCode, Email) Values("'" + Name + "', '" + Country + "', '" + Address + "', '" + City + "', '" ++ State + "', '" ++ PostCode + "', '" + Email + "')"

1 Like

it doesnt work, not sure what is the issue

Can you show me the properties of the query activity?

Also add an If statement after the connection to check connection (i.e. DatabaseConnection IS NOTHING
If True Log “Not Connected”

1 Like

@Heena_Saini

I checked the script and its totaly fine.Have you try it to your backend just a trial and error only to know where’s the problem occured?

cheers :smiley:

Happy learning :smiley:

3 Likes

@pattyricarte
when I run the insert query in database, it works fine and I have tried it using UiPath, it doesn’t work, same error it throws.
trying from backend means exactly what I have to do?

1 Like

Hi
Hope this expression would help you
“INSERT Into [ANZ CMD Legal].[dbo].[ContactDetails] (Name, Country, Address, City, State, PostCode, Email) Values (@Name, @Country, @Address, @City, @State, @PostCode, @Email)”

Cheers @Heena_Saini

1 Like

I would recommend you to store the SQL command in a string variable and verify it before execution e.g. using a WriteLine.

Cheers

1 Like

Hi @Heena_Saini

Have your try to look at this document.

cheers :smiley:

Happy learning :smiley:

2 Likes

Also here @Heena_Saini

I try to explore your issue and got this.

It shows how it converts the parameter to supply your column.

cheers :smiley:

Happy learning :smiley:

2 Likes

Hi @Heena_Saini,

In the below thread has the sample . May it help you.

Regards
Balamurugan.S

1 Like

Hi All,
Thank you very much for your replies and solutions.
It helped a lot and was able to solve the problem.
You guys are the best, all being busy though, comes forward to help fellow developers solve their problems, even though it is none of your concern.
Thanks a lot.

Issue has been resolved.

Earlier, I was using directly variables in the query, so was getting some error.
Now, I am passing it as Parameters.

Query used:
“INSERT Into [ANZ CMD Legal].[dbo].[ContactDetails] (Name, Country, Address, City, State, PostCode, Email) Values (@Name, @Country, @Address, @City, @State, @PostCode, @Email)”

Let me know if its clear so it can help others as well.

Happy Coding!! :slight_smile:

5 Likes