Solved

Object reference not set to an instance of an object

Posted on 2006-11-17
4
191 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 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

Industry Leaders: 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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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