Getting error while using insert query to add the values to the database column

Hi Team,

I am extracting table data from web page and fetching few column values through assign activity and store it in variableName. Now I am trying to insert the values(VariableName) to database columns using insert query but getting error.
below is the query I used.
in Execute Non Query activity:

“Insert into Tablename(columnName) values(” & VariableName & ") "
Also I try with

“UPDATE TableName SET ColumnName = " & VariableName & " WHere ColumnName is NULL”

Both are throwing error like Execute Non Query: Invalid column name ‘VariableName’.

Please help.

Thanks.

Hi @Nancy29

Try using [VariableName] or ‘VariableName’

Thanks

Hello @nancy29
If you have space in column name then add column name like this : [column name]
And also check name of the column is exactly same as name of column in database.

Thank you

Thank you for your reply.

Let me try it.

Hi ,
I changed the insert query as below.
“Insert into tablename([ColumnName],[ColumnName1]) values(‘VariableName’,‘VariableName1’)”. The existing error got solved. But I am getting below error Since one of the Column Value is Date format. Can you please help on this.

Execute Non Query: Conversion failed when converting date and/or time from character string.

Thanks

Hi @Nancy29

“Insert into tablename([ColumnName],[ColumnName1]) values(‘“+VariableName+”’,‘“+VariableName1+”’)”

Assuming these VariableName and VariableName1 are being retrieved in runtime, you would have to pass it like this.

I guess this should work

Convert your string variable into datetime coz in database you have specify column type as datetime
Or
You can change datetime column to string in database then above query will work

Hi @Nancy29

The error you are encountering in UiPath is likely due to incorrect string concatenation in your SQL query. To resolve the issue, you need to ensure that the value of VariableName is properly included in the query. Here’s the corrected format for your queries:

For the insert query:
“INSERT INTO TableName (ColumnName) VALUES ('” & VariableName & “')”

Make sure to replace TableName with the actual name of your table and ColumnName with the appropriate column name.

For the update query:
“UPDATE TableName SET ColumnName = '” & VariableName & “’ WHERE ColumnName IS NULL”

Thanks!!

Thank you All for your help.

It worked successfully when I used the below query.

“Insert into tablename([ColumnName],[ColumnName1]) values(‘“+VariableName+”’,‘“+VariableName1+”’)”.

Thanks.

Thank you.

Thank you for your suggestions.

Thankyou for your suggestion.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.