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

  • Home
  • SEARCH
  • 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 799193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:05:16+00:00 2026-05-14T23:05:16+00:00

In my aspx page I have a HTML inputfile type which allows user to

  • 0

In my aspx page I have a HTML inputfile type which allows user to browse for a spreadsheet.Once the user choses the file to upload I want to read the content of the spreadsheet and store the content into mysql database table.

I am using the following code to read the content of the uploaded file and convert it into a datatable in order into insert it into database table.

if (filMyFile.PostedFile != null)
        {
            // Get a reference to PostedFile object
            HttpPostedFile myFile = filMyFile.PostedFile;

            // Get size of uploaded file
            int nFileLen = myFile.ContentLength;

            // make sure the size of the file is > 0
            if (nFileLen > 0)
            {
                // Allocate a buffer for reading of the file
                byte[] myData = new byte[nFileLen];

                // Read uploaded file from the Stream
                myFile.InputStream.Read(myData, 0, nFileLen);

                DataTable dt = new DataTable();

               MemoryStream st = new MemoryStream(myData);
               st.Position = 0;
               System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
               dt=(DataTable)formatter.Deserialize(st);
}
}

But I am getting the following error when I am trying to deserialise the byte array into datatable.

Binary stream ‘0’ does not contain a valid BinaryHeader. Possible causes are invalid stream or object version change between serialization and deserialization.

Could someone please tell me what am I doing wrong?

I’ve also tried converting the bytearray into string ,then converting the string back to byte array and convert into datatable.That is also throwing the same error.

Thanks.

  • 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-05-14T23:05:17+00:00Added an answer on May 14, 2026 at 11:05 pm

    What makes you think that you can deserialize a spreadsheet into a datatable? You can most definitely not! All you need to do is to save the byte[] (myData) to a VARBINARY column in an appropriate table in your mysql database.

    EDIT

    You can do something along these lines:

    Suppose you have a mysql table:

    create table MyTable(
       Id INTEGER AUTO_INCREMENT
       SpreadSheet BLOB 
    ) ENGINE=InnoDB;
    

    You could use the following code to insert the uploaded file into the table:

    string strConn="PROVIDER=MySQLProv;SERVER=192.168.1.8;DB= test;UID=test;PWD=;PORT=;";
    OleDbConnection objConn;
    objConn=new OleDbConnection (strConn);
    objConn.Open();
    string sql="INSERT INTO MyTable (SpreadSheet) VALUES(?)";
    OleDbCommand cmd = new OleDbCommand(sql,objConn);
    OleDbParameter param = new OleDbParameter ("@image",OleDbType.Binary );
    param.Value = myData;
    cmd.Parameters.Add(param);
    cmd.ExecuteNonQuery();
    objConn.Close ();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 483k
  • Answers 483k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have a (small) stack of machine detectable errors. It… May 16, 2026 at 6:58 am
  • Editorial Team
    Editorial Team added an answer The one line below will do a case insensitive word… May 16, 2026 at 6:58 am
  • Editorial Team
    Editorial Team added an answer I've solved it like this. On server side, process authentication… May 16, 2026 at 6:58 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.