Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8176785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:19:38+00:00 2026-06-06T23:19:38+00:00

I want to save a multidimensional byte array to a SQL Server database. I

  • 0

I want to save a multidimensional byte array to a SQL Server database.

I know how to save a byte array which is a image conversion to a database. For that the data type I used is image. But now I want to store another byte array which is multidimensional byte array byte [,] temp, which has two dimensions with x,y values.

I searched on internet and here, it is said that using VARBINARY format. All I want to know is if I save my multidimensional array in a VARBINARY datatype data column, will the values will be altered? Is it possible to receive the data back as multidimensional array again?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:19:39+00:00Added an answer on June 6, 2026 at 11:19 pm

    Yes, you will be able to get back your multi-dimensional array unaltered.

    How can you do it? Using a Varbinary(max) field in Sql Server and saving into it the serialized multidimensional byte array. In order to get your array back, obviusly, you need to deserialize what you stored in the database.

    Here is an example of how to do it:

    public void TestSO()
    {
        using (SqlConnection conexion = new SqlConnection())
        {
            using (SqlCommand command = new SqlCommand())
            {
                //This is the original multidimensional byte array
                byte[,] byteArray = new byte[2, 2] {{1, 0}, {0,1}};
                ConnectionStringSettings conString = ConfigurationManager.ConnectionStrings["ConnectionString"];
                conexion.ConnectionString = conString.ConnectionString;
                conexion.Open();
                command.Connection = conexion;
                command.CommandType = CommandType.Text;
                command.CommandText = "UPDATE Table SET VarBinaryField = @Content WHERE Id = 73 ";
                command.Parameters.Add(new SqlParameter("@Content", SqlDbType.VarBinary, -1));
                //Serialize the multidimensional byte array to a byte[]
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, byteArray);
                //Set the serialized original array as the parameter value for the query
                command.Parameters["@Content"].Value = ms.ToArray();
                if (command.ExecuteNonQuery() > 0)
                {
                    //This method returns the VarBinaryField from the database (what we just saved)
                    byte[] content = GetAttachmentContentsById(73);
                    //Deserialize Content to a multidimensional array
                    MemoryStream ms2 = new MemoryStream(content);
                    byte[,] fetchedByteArray = (byte[,])bf.Deserialize(ms2);
                    //At this point, fetchedByteArray is exactly the same as the original byte array
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am retrieving an array values from database which save multi dimensional array..i want
I want to use a variable-sized multi-dimensional array in my app to save data.
I want to save some data into sqlite database and the read it, there
I want to save a setting in MS SQL for .net Color. What data
I have the following data which I want to save in my DB (this
Possible Duplicate: Save my cookie data to MySQL database? I want save data into
i want to save a byte[] in a table of SQLite Database (Field datatype
I want to save a multidimensional array to a file. A struct for example:
I want to save user image into a database in C#. How do I
I want to save and load my xml data using XmlReader. But I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.