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 9324061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:30:07+00:00 2026-06-19T04:30:07+00:00

In this code i wanted to save the image in picturebox1 in database using

  • 0

In this code i wanted to save the image in picturebox1 in database using linqtosql ….. but getting some exceptions in converting a image to byte array

Exception is “System.NullReferenceException: Object reference not set to an instance of an object.”

private void button1_Click(object sender, EventArgs e)

{
    DataClasses1DataContext dc = new DataClasses1DataContext();
    try
    {
        string signname = textBox1.Text;
        string imageurl = textBox2.Text;
        pictureBox1.ImageLocation = imageurl;
     //   byte[] file_byte = new byte[1000];
       // Image newimage = new Image(pictureBox1.Image);
    ///Error comes here
     byte[] file_byte = ImageToByteArray(pictureBox1.Image);
        System.Data.Linq.Binary file_binary = new                                                           System.Data.Linq.Binary(file_byte);


        Sign_Table obj = new Sign_Table()
        {
            Sign_Name = signname,
            Sign_Image = file_binary,

        };
        dc.Sign_Tables.InsertOnSubmit(obj);

    }
    finally
    {
        dc.SubmitChanges();
    }

}
private byte[] ImageToByteArray(Image imageIn )
{
    using (MemoryStream ms = new MemoryStream())
    {

           // Error comes here
        imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        return ms.ToArray();
    }

}
  • 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-19T04:30:08+00:00Added an answer on June 19, 2026 at 4:30 am

    I suspect the problem is that pictureBox.Image is null when you reference it. You are setting pictureBox.ImageLocation but not actually loading the image.
    Add a call to pictureBox.Load() immediately after setting pictureBox.ImageLocation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to generate a list view using below code. But after running this
I'm using mootools 1.4.3 for basic class inheritance. I'm actually converting some code from
I have this code private void saveImage() { Bitmap bmp1 = new Bitmap(pictureBox.Image); bmp1.Save(c:\\t.jpg,
I found this nice, working piece of code on this site but I wanted
I wanted to list all my Recently Used Items. I use this code: public
I've tried everything and it still fails! What's wrong with this code?!?! I wanted
This code fails on some machines: // Parse error: syntax error, unexpected '[' ...
This code : http://jsfiddle.net/bYtTG/1/ Works as I want in FF, chrome and opera, but
here is post my code:this is no the entire code but enough to explain
My application need to download some files to cache. but i wanted to check

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.