Convert/cast string to binary

I have a table with fields varbinary (i cant change the column type). I use LINQ and I want to assign the database column to a textbox value...so I do this:

IncomingPatient ip = new IncomingPatient(); //this is the table
//ip.firstname Binary

ip.firstname = first_name.Text
I get this error: Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary'

I've been googling and someone here is saying to change the Binary to Byte[]
http://forums.asp.net/t/1373602.aspx/1

How can I do this? do i need to change to Byte[]?
LVL 8
CamilliaAsked:
Who is Participating?
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, well, have you tried this?:
IncomingPatient ip = new IncomingPatient(); //this is the table
ip.firstname = new System.Data.Linq.Binary(System.Text.Encoding.UTF8.GetBytes(first_name.Text));

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.