How to check whether the data is already present in database

I am using UiPath and MS sql for storing data now i want to check whether a value is exist in column or not in database.

hi @shruti.garg

  • for each row in yourDT
  • if row(“yourHeader”)=“your value”
  • then assign var=“True”
  • Break

Hi @shruti.garg ,

Can you try this,

For UiPath

boolVar = If(DT.AsEnumerable().Where(Function(x) x(“YourColumnName”).ToString=“YourexpectedValue”).count>0,True,False)

For database:

Select Count(Columnname) in yourtable
Where columnname = yourexpectedvalue

Thanks

I have a form where i am using aadharnumber that is a string, now i want to check whether this number is already exist or not.

Hi @shruti.garg ,

If you need to compare aadharnumber with Datatable specific column, You can use below expression.

If(DT.AsEnumerable().Where(Function(x) x(“YourColumnName”).ToString=“aadharnumber ”).count>0,“aadharnumber already exist”,“aadharnumber not exist”)

Hi @shruti.garg

Follow these steps:

  1. Connect database
  2. For each row in datatable or excel:
  3. Use execute query activity
    SELECT COUNT(*) FROM TableName WHERE ColumnName = CurrentRow(""col_name)
    The result will be stored in a DataTable variable. You can access the value in the result table using the index result.Rows(0)(0)
  4. Use if condition:
    If CInt(result.Rows(0)(0)) > 0 Then follow further
    else: Another set of instructions