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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:49:35+00:00 2026-05-31T07:49:35+00:00

Friends I had a datagridview in my windowsdesktop application to insert data into the

  • 0

Friends
I had a datagridview in my windowsdesktop application to insert data into the database. when i click the add button validation should be done to ensure that no cells are left empty .I am not using cellvalidatorevent since i think its complicating process
i had written code like this

public void validateDatagrid()
        {
            if (tblpurchaserequest.RowCount == 1)
            {
                lblstatus.Text = "There is No  Purchase Data to Add";

            }
            else
            {
                for (int i = 0; i < tblpurchaserequest.RowCount; i++)
                {



                    if (tblpurchaserequest.Rows[i].Cells[0].Value.ToString().Trim() == "" || tblpurchaserequest.Rows[i].Cells[1].Value == null)
                    {
                        lblstatus.Text = "Please Enter Item in " + i + "th ROW";
                    }

                    if (tblpurchaserequest.Rows[i].Cells[0].Value.ToString().Trim() == "" || tblpurchaserequest.Rows[i].Cells[2].Value == null)
                    {
                        lblstatus.Text = "Please Enter Description in " + i + "th ROW";
                    }
                    if (tblpurchaserequest.Rows[i].Cells[0].Value.ToString().Trim() == "" || tblpurchaserequest.Rows[i].Cells[3].Value == null)
                    {
                        lblstatus.Text = "Please Enter Supplier in " + i + "th ROW";
                    }
                    if (tblpurchaserequest.Rows[i].Cells[0].Value.ToString().Trim() == "" || tblpurchaserequest.Rows[i].Cells[4].Value == null)
                    {
                        lblstatus.Text = "Please EnterQuantity in " + i + "th ROW";
                    }
                }
            }

        }

but this is giving exception
Object reference not set to an instance of an object.
pls advice me my mistake

  • 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-31T07:49:36+00:00Added an answer on May 31, 2026 at 7:49 am

    Obviously some value is null and the way you do the check in your if clause would need to be in a different order.

    Change from:

    if (tblpurchaserequest.Rows[i].Cells[0].Value.ToString().Trim() == "" 
        || tblpurchaserequest.Rows[i].Cells[1].Value == null) 
    

    to:

    if (tblpurchaserequest.Rows[i].Cells[1].Value == null
        || tblpurchaserequest.Rows[i].Cells[0].Value.ToString().Trim() == "") 
    

    That is, check for NULL first. This will ensure that the second part in your if does not get evaluated, if the first part indeed returns a null (which is giving you an “object reference blah blah” error)

    You will need to reverse the order on all if statements in your code block.

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

Sidebar

Related Questions

Hii Friends, the application is that using a imageviewer of a which had placed
I had an argument with one of my friends who is an architect at
A friend of mine had a report done on an old site I built.
I am trying to use the FB.ui() to send apprequests to friends. My application
Some friends and I have had an idea for a website and have started
I have a form that allows users to refer friends. I want to add
I have a form that allows users to refer friends. I want to add
Hello friends i am using https server data using JSOn webservice but i don't
I had stored custom objects data in Array. I am fetching data from Array
I've finally had a second to look into streaming, daemons, and cron tasks 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.