Solved

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

Posted on 2006-11-17
12
1,932 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
install app on other machine 13 32
Split string on commas but not when enclosed in parentheses 7 48
Error on link 14 38
Best resource to learn entity framework 2 0
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

17 Experts available now in Live!

Get 1:1 Help Now