How to retrieve SQL server OID data into string format?

Hi all, I’m very new to both UiPath and SQL server, and help needed here to advice on how to get OID data from SQL server table in string format.

Case:
in SQL server table, for example, the OID is 0xABCDEFG123
but when using “assign” in UiPath to retrieve this data, it will show System.Byte instead of showing 0xABCDEFG123.
the assign formula i’m using is: OID_string = DT.Rows(0).item(“columnname”).tostring

Hi @cyicyi

I assume you want OID in string format but you are receiving it in System.Byte format right.

you can extract string from the byte format using this code.

System.Text.Encoding.UTF8.GetString(byteArray);

hii thanks for ur reply, but before that need another advice on how could i retrieve the OID from the SQL table as byte array?

Currently i’m only know how to get the OID from SQL server table as object/string causing below error:

I’ve set the variable type of the testOID to system.byte.

Can you try this and let me know what result you are getting.

System.Text.Encoding.Default.GetBytes(SQLTestDT.Rows(0).Item(0).ToString)

Hi, thanks! But I’ve tried and still showing system.byte.
image

image

Can you see what is the data type of the OID in the data table if its a string you can directly get string using SQLTestDT.Rows(0).Item(0).ToString
Make the testOID as String variable.

it might be better to convert the OID Directly within the SQL like

convert(nvarchar(36), YourOIDColName) as OIDSTRING

yea i used this at first and keep getting system.byte as result

hi, could u provide more details on this like how could i use this in SQL server? sorry because i’m really quite new to SQL…

share with us the used SQL, thanks

it’s just a simple one

SELECT
[test_OID]

FROM test.table

so you can try

SELECT convert(nvarchar(36), [test_OID]) as OIDSTRING
FROM test.table

For SQL RnD we recommend any SQL Client
For RnD within UiPath Studio we recommend:

hi i’ve tried the way u suggested, but i gt some strange output

and when i’m retriveing from UiPath, it still showing system.byte as result:
image

image

We highly recommend to start working with the debugging panels e.g. the immediate panel

when working with a complex complex datatype ( e.g. an Array of X) the ToString() is NOT returning a representation of items, but the DataType Name instead

This you can clearly see within the logs

Also when the DataTable Column value is a complex DataType we have to cast it for the retrieval like

DirectCast(SQLtestDT.Rows(0)(0), Bytes() )

From above we cannot derrive any relationship between first and second screenshot, but you can still try to use other conversion approaches like the Cast method