varbinary to nvarchar to string

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)
 
J

Jon Skeet [C# MVP]

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').
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top