Object reference not set to an instance of an object

Hi experts,

I got the above error while running this code.

private void btnCheckOut_Click(object sender, System.EventArgs e)
            {
                  if (!(dsCustomers.Tables["Customers"].Rows.Contains(txtEmail.Text))) ===>highlighted
                  
                  {
                        BAL.Customer Customer = new BAL.Customer();
                        this.SetCustomerValues(Customer);
                        DAL.HalloweenDB.AddCustomer(Customer);
//                        sEmail = Session["Email"];
//                        if (sEmail != txtEmail.Text & sEmail != "")
//                        {
//                              HalloweenDB.DeleteCustomer(sEmail);
//                        }
//                        Session.Remove("Customers");
//                  }
//                  else
//                  {
//                        if (CustomerModified())
//                        {
//                              Customer Customer = new Customer();
//                              this.SetCustomerValues(Customer);
//                              HalloweenDB.UpdateCustomer(Customer);
//                        }
                  }
                  //lblCheckOut.Text = "The remaining check out functions have not been implemented.<br>" + "Click Cancel Order to start a new order, or Continue Shopping<br>" + "to modify your order.";

            }
I am basically trying to insert some items into a sql.

How do i solve this
thanks

SirReadAlotAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Razzie_Connect With a Mentor Commented:
rewrite your if statement to:

if (!dsCustomers == null && !dsCustomers.Tables["Customers"] == null && !dsCustomers.Tables["Customers"].Rows.Contains(txtEmail.Text))


This should get rid of the error.

HTH,
Razzie
0
 
ozymandiasCommented:
One of the following :

the DataSet dsCustomers is null
there is no table called "Customers"
the object txtEmail is null (or possibly its .Text property but this is less likely)
0
 
SirReadAlotAuthor Commented:
hi

there is no table called "Customers"== this exits

how do i know its
the object txtEmail is null (or possibly its .Text property but this is less likely)

0
 
ozymandiasCommented:
You need to check to see if any of the values I have identified above are null before you attempt to use them.
I see you are already asking this in another question.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.