Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Object reference not set to an instance of an object

Posted on 2006-11-17
4
Medium Priority
?
193 Views
Last Modified: 2010-04-16
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

0
Comment
Question by:SirReadAlot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17968817
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
 

Author Comment

by:SirReadAlot
ID: 17968845
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
 
LVL 15

Expert Comment

by:ozymandias
ID: 17969219
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
 
LVL 8

Accepted Solution

by:
Razzie_ earned 2000 total points
ID: 17970926
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question