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

Concat 3 binary fields

The solution in the related question works but now I need to concat 3 binary fields..They're phone numbers. How can I do this?

ip.phone is varbinary in the database
ip.Phone = new Binary(Encoding.UTF8.GetBytes(phone1.Value) & (Encoding.UTF8.GetBytes(phone2.Value) & (Encoding.UTF8.GetBytes(phone3.Value));

Open in new window

0
Camillia
Asked:
Camillia
  • 3
1 Solution
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, If the Value property is string, then try:
ip.Phone = new Binary(Encoding.UTF8.GetBytes(phone1.Value + phone2.Value + phone3.Value));

Open in new window

0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Otherwise if Value is byte[], then try:
ip.Phone = new Binary(Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(phone1.Value) + Encoding.UTF8.GetString(phone2.Value) + Encoding.UTF8.GetString(phone3.Value)));

Open in new window

0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Also, if Value is a System.Data.Linq.Binary type, then try:
ip.Phone = new Binary(Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(phone1.Value.ToArray()) + Encoding.UTF8.GetString(phone2.Value.ToArray()) + Encoding.UTF8.GetString(phone3.Value.ToArray())));

Open in new window


Reference:
http://msdn.microsoft.com/en-us/library/system.data.linq.binary.toarray.aspx
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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