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 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[]

How can I do this? do i need to change to Byte[]?
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

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.