Need Help on compare Excel data with SQL DB server data using primary key and update excel row into Database

Hi experts,

I need help on comparing excel data with existing MS SQL server DB using primary key column. If match found record should update in MS SQL DB from excel sheet.


Welcome to forums

For establishing the connection to SQL server and UiPath to query the database check below

Once the configuration done you can use Datatable activities to query the DB

Use Read Range activity to read the excel sheet and create an output variable which is of type Datatable let’s say dtExcelData

Once done you can use Execute query activity and create a variable in output which is a datatable let’s say dtSQLData
inside that pass the query as For example

Select * from database name where ID = ‘201’

The results will store in the dtSQLData variable

Use If condition to check whether it has the rows or not

like dtSQLData.Rows.Count > 0

This will represents the results has the rows

Else will be no rows and you can skip

You can use For Each row activity and compare each value of the dtExcelData

and use Execute non query activity you can write a update statement

Hope this may help you


1 Like