Solved

Object reference not set to an instance of an object

Posted on 2006-11-17
4
186 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
  • 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 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now