?
Solved

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

Posted on 2006-11-17
12
Medium Priority
?
1,974 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
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!

 

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

Independent Software Vendors: 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 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