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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:35:12+00:00 2026-05-30T14:35:12+00:00

I have downloaded this PictureBox ImageArray then I’ve added a button which will add

  • 0

I have downloaded this PictureBox ImageArray
then I’ve added a button which will add all it’s image to sql server 2005

this is the code:

private System.Windows.Forms.PictureBox[] imgArray2;
string c_string = "server=.\\sqlexpress;database=Blue;trusted_connection=true";


for (int i = 0; i < NumOfFiles; i++)
{
    imgArray2[i].Image = Image.FromFile(imgName[i]);
    string name = imgName[i].Substring(imgName[i].LastIndexOf(@"\") + 1, imgName[i].Length - imgName[i].LastIndexOf(@"\") - 1);
    MemoryStream mstr = new MemoryStream();
    imgArray2[i].Image.Save(mstr, imgArray2[i].Image.RawFormat);
    byte[] arrImage = mstr.GetBuffer();
    string cmd = "insert into Images (ImagePart" + i + "Name, ImagePart" + i + ") values (@PName, @Pic)";

    SqlConnection c = new SqlConnection(c_string);
    SqlCommand comm = new SqlCommand(cmd, c);
    comm.Parameters.Add(new SqlParameter("@PName", SqlDbType.VarChar, 40)).Value = name;
    comm.Parameters.Add(new SqlParameter("@Pic", SqlDbType.Image)).Value = arrImage;

    try
    {
        c.Open();
        comm.ExecuteNonQuery();
    }
    catch (System.Data.SqlClient.SqlException err)
    {
        MessageBox.Show(err.Message);
    }
    finally
    {
        c.Close();
    }

}

I’ve added an imgArray2[] so the image from imgArray[] won’t changes and even though I’m using imgArray[] it still throwing the Null error.

The error info highlights the imgArray2[i].Image = Image.FromFile(imgName[i]);
it shows nullreferenceexception was unhandled – Object reference not set to an instance of an object.

  • 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-30T14:35:14+00:00Added an answer on May 30, 2026 at 2:35 pm

    The imgArray value and it’s contents are never initialized. It needs to be an array capable of holding at least NumFiles items and each item needs to be initialized.

    imgArray2 = new System.Windows.Forms.PictureBox[NumFiles];
    for (int i = 0; i < NumOfFiles; i++)
      imgArray2[i] = new System.Windows.Forms.PictureBox();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one spritesheet image with all sprites, I downloaded this image from
What does this mean: Next add reference to: MySql.Data actually I have downloaded mysql
I have downloaded and added this very simple, one file, php web file explorer
I have downloaded this API . If you go to lib/Paypal/Profile/Handler/Array.php you will find
Hay all, this is really bugging me. I have downloaded phpimage from http://sourceforge.net/tracker/index.php?func=detail&aid=2844769&group_id=103281&atid=738747 I've
I have downloaded the silver light from this http://www.microsoft.com/silverlight// I need to use this
I have a site, from which you can download an HTML file. This HTML
I have downloaded ZXing 1.5 and am trying to include this in my iPhone
i have downloaded a website using HTtrack wepsite copier. All files are downloaded to
I have downloaded the Fluent NHibernate source distribution, compiled all projects in solution and

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.