Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-17
12
Medium Priority
?
1,984 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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 2000 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 Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

618 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