Error while inserting to the database

Hi Guys,

I have been inserting data into a sql database, everything as been going fine so far however I uncounted this error.

Please you assist, it walking perfectly fine so I am unsure where the syntax is coming from.

Microsoft.Data.SqlClient.SqlException: Incorrect syntax near ‘)’. at UiPath.Database.Activities.ExecuteNonQuery.HandleException(Exception ex, Boolean continueOnError)
at UiPath.Database.Activities.ExecuteNonQuery.ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
at UiPath.Database.Activities.AsyncTaskCodeActivity.EndExecute(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

Hi @Aki1111 ,

Could you maybe provide us with the Expression that was used ?

It seems there is an error near a Bracket or Are you using the Bulk Insert Activity ?

@Aki1111

Are you passing any dynamic data?

If yes may be that data contains special characters like single quote or etc…

If so we need to eacape them like for single quote add double single quotes or use a slash(\)

Cheers

If(IsDBNull(CurrentRow.Item(0))OrElse String.IsNullOrEmpty(CurrentRow.Item(0).ToString()),“0”,CurrentRow.Item(0).ToString())

This was the expression that I used.

@Aki1111 ,

If you are using the Run Command activity, then you would require to use an SQL Query for the Insertion of data into Database table.

Check the below post on using the INSERT Statement :

Hi,

Yes I have done that,

“INSERT Into [dbo].[temp_InvoiceItems]
([invoice_no]
,[qty_ordered]
,[qty_shipped]
,[item_number]
,[item_description]
,[unit_price]
,[line_total])
VALUES
(”+“'”+InvoiceNo.ToString()+“'”+“, “+quantityOrdered+”,”+quantityShipped+“,”+“'”+itemNumber.ToString()+“'”+“,”+“'”+itemDescription.ToString()+“'”+“,”+unitPrice+“,”+lineAmount+“)”

I assigned the variables to expression i sent to you

Hi,

so the issue is with this part of the workflow,

“INSERT Into [dbo].[temp_InvoiceHeader]
([invoice_no]
,[subtotal]
,[vat]
,[total])
VALUES
(”+“'”+InvoiceNo.ToString()+“'”+“, “+SubTotal+”,”+vat+“,”+totalAmount+“)”

Vat := dt2.Rows(0).Item(0).ToString

Yes from a datatable,

I assigned a string variable to this dt2.Rows(0).Item(0).ToString

how can I make changes to this to ensure that data gets added?

@Aki1111

Can you first print the data and then check for any special characters in it…mostly i feel its the wingle quote preensent in the string if so say your data is abc’d then use dt.rows(0)(0).Tostring.Replace("’","’’")

Cheers