Solved

Object reference not set to an instance of an object

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

772 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