How to Take values from from database and assign it using column name

Hello guys…
need help to take value from database

I have set db connection as below


I have fill that values here by using column name I tried use datatable.columns(“col name”).columnname
as below img …pls correct me if I am wrong.
image

Getting below Error…
image

Please Help…

hi @prashantP

Give like this

GuestDatatable.Columns(“Firstname”).ColumnName=temp
(or)

you can give like this

row(“Firstname”).ToString=temp

Thanks
Ashwin S

Hi @AshwinS2

You mean
1 method :-


2. method :-

Please correct me…

What do you want to achieve by this assign?

temp = GuestDatatable.Columns(“Firstname”).ColumnName

Instead of passing the variable temp in the last screenshot, pass it as row(“column name”).tostring

Row is the each row values which you will get while looping the data table , so if you use row outside, you will get the row as null. @prashantP

the assignment with assign activity looks correct
we need to check with the datatable variable used in it
because this error states that the activity having this error has a variable with null values in it
that is the datatable variable GuestDatatable has no value in it

before to this assign activity use a writeline activity and mention like this
String.IsNullOrEmpty(GuestDatatable.Columns(“First Name”).ColumnName.ToString).ToString

if it display as TRUE in the output panel then there is no data or even a column schema structure in that variable

make sure that the variable temp is with global scope in the variable panel
kindly check that once and let know pls
cheers @prashantP

This means that there is no column with name “First Name” in the returned datatable.

I can’t verify now but I recall that column names with space are not handled properly by UiPath.Database.Activities - only the first word is assigned as column name in resulting datatable.

To verify try the following
GuestDatatable.Columns(“First”).ColumnName

Cheers

I verified now and it works okay in UiPath.Database.Activities 1.2.6863.32528

So the only reason could be that there is no column with name “First Name”…

Cheers

Hi @AshwinS2 and @J0ska

Yes. there is no space between First & Name. (“FirstName”) is working…

but it is not taking values from that column it type FirstName & LastName.
check below.
image

table having values check below
image

kindly check and let me know the corrections please.

So it comes back to my question…

Do you want to get NAME of column “FirstName”?
Then the expression “GuestDatatable.Columns(“FirstName”).ColumnName” gives you this.

Do you want to get VALUE of column “FirstName”?
Then use following expression in the For Each Row
“row.item(“FirstName”)”

Hi @J0ska thanks…

already used row.item(“First Name”)” but there is space before that’s why it was not work…

Glad to hear.

BTW this is basics of any coding…
1/ Verify my data - Is it really what I expect?
2/ Verify my inputs - Is it typo free?

…and only after that asking for help.

Cheers

hello @J0ska
I need one more help from you.
I am trying to scrap data from web page…

I just changed attr=‘text’ to attr=‘value’
<column name=‘Column1’ attr=‘value’

now the problem is i want to print or use that data to proceed further but using tosting it’s not printing
refer below img for reference


pls let me know…

thanks
Assetsoft

This is different topic → raise a new question.

Cheers

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