Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1186
  • Last Modified:

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

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


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now