Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have placed this code under the insert button that transfers the values from the textboxes to the datagridview.
 
for (int nCounter = 0; nCounter <= dataGridView1.RowCount - 1; nCounter++)
            {
                if (txtrawmatno.Text == dataGridView1[2, nCounter].Value.ToString())
               {
                    MessageBox.Show("That product has been selected already.", "Repeat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
 
            }
 
I'm getting an error that says: Object reference not set to an instance of an object.
please help! I want to validate the text box value to avoid entering a duplicate.
Posted 15-Jul-12 5:49am
wolfsor564

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 15 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100