varbinary to nvarchar to string

  • Thread starter Thread starter Sunit Joshi
  • Start date Start date
S

Sunit Joshi

Hello All
I have a field which is of type varbinary(256). Now in my sql
statement I cast it to nvarchar but when do the DataReader.GetString()
method, I get the string with \0 at the end.

This is what I do in the SQL statement
cast(S.ObjectMoniker as nvarchar(100)) as Filepath

When I try this
string filename = oDbReader.GetString(iFilePathOrdinal)

I get the filenam as \\test\filename1\0

any ideas what I need to do here..??

thanks
Sunit
(e-mail address removed)
 
Sunit Joshi said:
I have a field which is of type varbinary(256). Now in my sql
statement I cast it to nvarchar but when do the DataReader.GetString()
method, I get the string with \0 at the end.

This is what I do in the SQL statement
cast(S.ObjectMoniker as nvarchar(100)) as Filepath

When I try this
string filename = oDbReader.GetString(iFilePathOrdinal)

I get the filenam as \\test\filename1\0

any ideas what I need to do here..??

I'm assuming you're not looking for "don't use a binary field for text
data" :)

You can trim the end with String.TrimEnd('\0').
 
Back
Top