Solved

Cannot implicitly convert type 'System.Data.DataTable' to 'bool'

Posted on 2006-11-17
12
1,921 Views
Last Modified: 2008-01-09
Hi experts, How do i go about solving this line of code?
private void btnCheckOut_Click(object sender, System.EventArgs e)
            {
                  if (dsCustomers.Tables["Customers"]) ========here
                  
                  {
                        BAL.Customer Customer = new BAL.Customer();
                        this.SetCustomerValues(Customer);
                        DAL.HalloweenDB.AddCustomer(Customer);

                  }
            
            }

thanks
0
Comment
Question by:SirReadAlot
  • 8
  • 4
12 Comments
 
LVL 29

Expert Comment

by:Nightman
ID: 17968994
What are you trying to do? A table cannot be true or false. Are you looking to check the value of one of the columns perhaps?
0
 

Author Comment

by:SirReadAlot
ID: 17969007
Are you looking to check the value of one of the columns perhaps? I was.

but now I just want to insert some items into the database
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17969020
if (dsCustomers.Tables["Customers"]!=null) //Checks if the object exists

Is that what you are looking for?
0
 

Author Comment

by:SirReadAlot
ID: 17969025
original 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.";

          }
0
 

Author Comment

by:SirReadAlot
ID: 17969038
will try you code
0
 

Author Comment

by:SirReadAlot
ID: 17969047
now it says
Object reference not set to an instance of an object.


if (dsCustomers.Tables["Customers"]!=null) //Checks if the object exists ======highlighted
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:SirReadAlot
ID: 17969064
this is the insert statment

public static object AddCustomer(BAL.Customer Customer)
            {
                  SqlConnection conHalloween = Connection();
                  SqlCommand cmdCustomer = new SqlCommand();
                  cmdCustomer.Connection = conHalloween;
                  cmdCustomer.CommandText = "Insert Into Customers Values ('" + Customer.Email + "', '" + Customer.LastName + "', '" + Customer.FirstName + "', '" + Customer.Address + "', '" + Customer.City + "', '" + Customer.State + "', '" + Customer.ZipCode + "', '" + Customer.PhoneNumber + "')";
                  conHalloween.Open();
                  cmdCustomer.ExecuteNonQuery();
                  conHalloween.Close();
                  return Customer;
            }
0
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 17969096
Try this:
if (dsCustomers!=null && dsCustomers.Tables["Customers"]!=null)

Is dsCustomers populated?
Does the "Customers" data table exist?
0
 

Author Comment

by:SirReadAlot
ID: 17969118
Is dsCustomers populated?
Does the "Customers" data table exist?

yes and there is data in it

i will try you code
0
 

Author Comment

by:SirReadAlot
ID: 17969165
it seems to have solved it,

but
private void btnCheckOut_Click(object sender, System.EventArgs e)
            {
                  if (dsCustomers!=null && dsCustomers.Tables["Customers"]!=null)
                  {
                        BAL.Customer Customer = new BAL.Customer(); ====this line is not called
                        this.SetCustomerValues(Customer);
                        DAL.HalloweenDB.AddCustomer(Customer);

                  }
            }
0
 
LVL 29

Expert Comment

by:Nightman
ID: 17969265
Well, clearly the problem is that it is evaluating that statement as false. So either dsCustomers is null or dsCustomers.Tables["Customers"] is null.
0
 

Author Comment

by:SirReadAlot
ID: 17969358
thanks

i did this

      if(!(dsCustomers!=null && dsCustomers.Tables["Customers"]!=null))
            
your is

if (dsCustomers!=null && dsCustomers.Tables["Customers"]!=null)

thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

18 Experts available now in Live!

Get 1:1 Help Now