You must Sign In to post a response.
  • Category: .NET

    How to convert varbinary to bytearray[] datatype

    Hi

    In my table photo column varbinary datatype how to convert using select query
    varbinary to bytearray.

    1.using select query varbinary to bytearray[]

    or

    2. i have 4 column in a table in the photo column when i get datatable
    i need only need to change varbinary to bytearray in the photo column.
  • #766800
    Hi,

    Is there any specific reason you are looking to convert in SQL server side, I guess it is some typical job, the easiest way to convert the same in C# code only, but as per your concern I Google it the solution they provide is available in below link, go through the below link this might be helpful to you.

    https://blogs.msdn.microsoft.com/sqltips/2008/06/30/converting-from-base64-to-varbinary-and-vice-versa/

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #766805
    HI,
    Use the following code. It may help u,
    SELECT CONVERT(VARBINARY(25), '0x9473FBCCBC01AF', 1);

    otherwise ,
    You can insert the Varbinary column value into Varchar column means it also will work.


    Regards,
    Karunanidhi.K

  • #766808
    Why you want this conversion in the DB side?. You can handle it in the BOL or UI layer that is the good practice .
    By Nathan
    Direction is important than speed

  • #766845
    I have done same case with the help of LINQ, see below
    1. Add reference into your project to System.Data.Linq.dll
    2. write a function to fetch value in MemoryStream
    see below code

    //just read it with DataReader or dataset and pass it to below function
    public static Image ConvertToImage(System.Data.Linq.Binary iBinary)
    {
    var arrayBinary = iBinary.ToArray();
    Image rImage = null;

    using (MemoryStream ms = new MemoryStream(arrayBinary))
    {
    rImage = Image.FromStream(ms);
    }
    return rImage;
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766861
    You have to use streams to convert varbinary into byte array
    SRI RAMA PHANI BHUSHAN KAMBHAMPATI


  • Sign In to post your comments