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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:07:45+00:00 2026-05-18T11:07:45+00:00

edittted: I already debug, I figure out that once I fill all the fields,

  • 0

edittted:

I already debug, I figure out that once I fill all the fields, autmatically generate a new row empty, and once it is stored in the dabase, it follow with the loop foreach, and automaticaly detect null reference this is an image, I hope you understand me img8.imageshack.us/i/error3xh.jpg

I need your help, I can’t control the exception,here is my method and the error say System.NullReferenceException: Object reference not set to an instance of an object”, how can I fix it, control the exeption, no more messages of this type?, no matter how its the structure : the error is the line ** if (combo3 == null || combo4 == null) **

alt text

private void btnCronograma_Click(object sender, EventArgs e)
{
  string connstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\amaury\\Documents\\TEC\\Septimo Semestre\\Administracion de proyectos de ingenieria de softwaere\\nuevo4\\nuevo\\Office\\Office\\Policias.accdb";
  using (OleDbConnection conn = new OleDbConnection(connstring))
   {
    conn.Open();

    string sql = "INSERT INTO IndicadorProyecto (idProyecto, idMes, meta, real) VALUES(@idProyecto , @idMes , @meta, @real)";
    OleDbCommand cmd = new OleDbCommand(sql, conn);

  foreach (DataGridViewRow row in dataGridView8.Rows)
  {
    DataGridViewComboBoxCell combo3 = row.Cells["idProyecto"] as DataGridViewComboBoxCell;
    DataGridViewComboBoxCell combo4 = row.Cells["idMes"] as DataGridViewComboBoxCell;

    if (combo3 == null || combo4 == null)
    {
        MessageBox.Show("No se pudo convertir");
        continue;
    }

  int idProyecto = int.Parse(combo3.Value.ToString());
  int idMes = int.Parse(combo4.Value.ToString());
  int meta = int.Parse(row.Cells[3].Value.ToString());
  int real = int.Parse(row.Cells[4].Value.ToString());  

  cmd.Parameters.Clear();
  cmd.Parameters.AddWithValue("@idProyecto", idProyecto);
  cmd.Parameters.AddWithValue("@idMes", idMes);
  cmd.Parameters.AddWithValue("@meta", meta);
  cmd.Parameters.AddWithValue("@real", real);


  cmd.ExecuteNonQuery();
  }
}
}

this is the complete error

Consulte el final de este mensaje para
obtener más detalles sobre cómo
invocar a la depuración Just-In-Time
(JIT) en lugar de a este cuadro de
diálogo.

************** Texto de la excepción ************** System.NullReferenceException:
Referencia a objeto no establecida
como instancia de un objeto. en
Office.Form1.btnCronograma_Click(Object
sender, EventArgs e) en
C:\Users\amaury\Documents\TEC\Septimo
Semestre\Administracion de proyectos
de ingenieria de
softwaere\nuevo4\nuevo\Office\Office\Form1.cs:línea
726 en
System.Windows.Forms.Control.OnClick(EventArgs
e) en
System.Windows.Forms.Button.OnClick(EventArgs
e) en
System.Windows.Forms.Button.OnMouseUp(MouseEventArgs
mevent) en
System.Windows.Forms.Control.WmMouseUp(Message&
m, MouseButtons button, Int32 clicks)
en
System.Windows.Forms.Control.WndProc(Message&
m) en
System.Windows.Forms.ButtonBase.WndProc(Message&
m) en
System.Windows.Forms.Button.WndProc(Message&
m) en
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&
m) en
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m) en
System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr
lparam)

  • 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-18T11:07:46+00:00Added an answer on May 18, 2026 at 11:07 am

    I think most likely cause is that row.Cells[3].Value or row.Cells[4].Value are null (since you have not given them a value) and .ToString() throws a null exception.

    Change the code to:

    int meta = int.Parse(row.Cells[3].Value == null ? "0" : row.Cells[3].Value.ToString());
    int real = int.Parse(row.Cells[4].Value == null ? "0" : row.Cells[4].Value.ToString());  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a universal for iphone/ipad and I already set the deployment target
I am trying to duplicate the site notice banner that is displayed on the
The context for my question is that of an alarm application but I would
I'm having some trouble figuring out the best way to do this, and I
Editted heavily! The original question was based on a misunderstanding of how IN() treats
I'm using Quartz.NET for a system I am creating, where jobs are run via
I have a select dropdown list from a taxonomy applied to multiple node types
I have a project ongoing at the moment which is create a Windows Service

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.