title: An unhandled exception of type 'System.ArgumentNullException' occurred in mscorlib.dll Additional information: Path cannot be null
body: <p>I got this error when I am trying to add a data to the database when the image in the picture box is empty, but when the picturebox contains a image, the system working well.</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.ArgumentNullException' occurred
    in mscorlib.dll</p>
    
    <p>Additional information: Path cannot be null.</p>
  </blockquote>
  
  <p>The error is pointed on:</p>
  
  <blockquote>
    <p>fsStream = new FileStream(this.imagePath, FileMode.Open,
    FileAccess.Read);</p>
  </blockquote>
  
  <p>Here is the code that I am using:</p>
  
  <pre><code>Random _random = new Random();
          Timer _timer = new Timer();
          Wait _wait = new Wait();
  
          FileStream fsStream;
          BinaryReader bReader;
  
          byte[] imageByte = null;
  
          string imagePath;
  
          string gender;
  
          string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\db1.accdb";
  
  private void button1_Click(object sender, EventArgs e)
          {
              using (OpenFileDialog dlg = new OpenFileDialog())
              {
                  dlg.Title = "Open Image";
                  dlg.Filter = "JPG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png|All Files (*.*)|*.*";
  
                  if (dlg.ShowDialog() == DialogResult.OK)
                  {
                      pictureBox1.Image = new Bitmap(dlg.FileName.ToString());
                      imagePath = dlg.FileName;
                  }
              }
          }
  
  
  public virtual void button2_Click(object sender, EventArgs e)
          {
              fsStream = new FileStream(this.imagePath, FileMode.Open, FileAccess.Read);
              bReader = new BinaryReader(fsStream);
              imageByte = bReader.ReadBytes((int)fsStream.Length);
  
              if (this.pictureBox1.Image == null || this.textBox2.Text == "" || this.textBox3.Text == "" || this.textBox4.Text == "" || this.textBox5.Text == "")
              {
                  System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                  _sound.Play();
  
                  DialogResult _dialogResult = MessageBox.Show("Cannot Submit!", "Warning", MessageBoxButtons.OK);
              }
  
              else if (this.label9.Visible == false)
              {
                  System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                  _sound.Play();
  
                  DialogResult _dialogResult = MessageBox.Show("You have to check the Student ID before proceeding!", "Warning", MessageBoxButtons.OK);
              }
  
              else if (this.label8.Visible == true)
              {
                  System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                  _sound.Play();
  
                  DialogResult _dialogResult = MessageBox.Show("You cannot use this Student ID. Please Get another Student ID instead!", "Warning", MessageBoxButtons.OK);
              }
  
              else if (this.label7.Visible == true)
              {
                  System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                  _sound.Play();
  
                  DialogResult _dialogResult = MessageBox.Show("Student ID is being verified! Please wait!", "Warning", MessageBoxButtons.OK);
              }
  
              else
              {
                  using (OleDbConnection conn = new OleDbConnection(connectionString))
                  {
                      string query = "INSERT INTO [Student] ([StudentID], [FirstName], [LastName], [Photo], [DateOfBirth], [Address], [JoinedDate], [Class], [Gender]) VALUES (@StudentID, @FirstName, @LastName, @Photo, @DateOfBirth, @Address, @JoinedDate, @Class, @Gender)";
  
                      conn.Open();
  
                      using (OleDbCommand cmd = new OleDbCommand(query, conn))
                      {
                          cmd.Parameters.Add("@StudentID", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@StudentID"].Value = this.textBox1.Text;
  
                          cmd.Parameters.Add("@FirstName", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@FirstName"].Value = this.textBox2.Text;
  
                          cmd.Parameters.Add("@LastName", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@LastName"].Value = this.textBox3.Text;
  
                          cmd.Parameters.Add("@Photo", System.Data.OleDb.OleDbType.LongVarBinary);
                          cmd.Parameters["@Photo"].Value = imageByte;
  
                          cmd.Parameters.Add("@DateOfBirth", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@DateOfBirth"].Value = this.dateTimePicker1.Text;
  
                          cmd.Parameters.Add("@Address", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@Address"].Value = this.textBox4.Text;
  
                          cmd.Parameters.Add("@JoinedDate", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@JoinedDate"].Value = this.dateTimePicker2.Text;
  
                          cmd.Parameters.Add("@Class", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@Class"].Value = this.textBox5.Text;
  
                          cmd.Parameters.Add("@Gender", System.Data.OleDb.OleDbType.VarChar);
                          cmd.Parameters["@Gender"].Value = gender;
  
                          _wait.ShowDialog();
  
                          System.Media.SoundPlayer _sound = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                          _sound.Play();
  
                          DialogResult _dialogResult = MessageBox.Show("Added Successfully!", "Success", MessageBoxButtons.OK);
  
                          cmd.ExecuteNonQuery();
                      }
  
                      conn.Close();
                  }
              }
          }
  </code></pre>
  
  <p>Here is the image:</p>
  
  <p><img src="https://i.stack.imgur.com/diROV.png" alt="enter image description here"></p>
  
  <blockquote>
    <p><strong>button1_Click is for Upload a Photo (The image will be shown in top</strong>
    <strong><em>right corner)</em></strong></p>
    
    <p><strong>button2_Click is for Submit (Adding data to the database)</strong></p>
  </blockquote>
  
  <p>Anyone can help me?</p>
  
  <p>Your answer much appreciated!</p>