Solved

List box not populating based on MySQL query

Posted on 2015-02-17
2
106 Views
Last Modified: 2015-02-17
I am attempting to query my database and return productID's based on the orderID. First I tried:
"SELECT productID FROM `Order` WHERE Order.orderID = Order.orderID"

But that returned all the productID's from all orders in the table. I currently have the following code but now the list box isn't returning any value.

 public static bool orderVerify(DropDownList ddlProductID)
    {
        MySqlConnection connection = new MySqlConnection("server=*****;user id=****;database=***;password=***;persistsecurityinfo=True");
        connection.Open();
        var cmd = new MySqlCommand("SELECT productID FROM `Order` WHERE orderID = 'orderID.Text'", connection);
        var reader = cmd.ExecuteReader();
        
        if (reader.HasRows)
         {
              DataTable dt = new DataTable();
              dt.Load(reader);
              ddlProductID.DataSource = dt;
              ddlProductID.DataValueField = "productID";
              ddlProductID.DataTextField = "productID";
              ddlProductID.DataBind();
    }
        connection.Close();
        return true;
    }

Open in new window

0
Comment
Question by:Robin Harris
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40615426
Hi,
sorry, I have no experience with MySQL queries (especially the table adressing and the quotes), but it should look like
var cmd = new MySqlCommand(String.Format("SELECT productID FROM `Order` WHERE orderID = '{0}'",orderID.Text), connection);

Open in new window

HTH
Rainer
0
 

Author Comment

by:Robin Harris
ID: 40615710
I got it. Here is the change I made:
var cmd = new MySqlCommand(String.Format("SELECT productID FROM `Order` WHERE orderID = '{0}'", orderID), connection);

Open in new window


I also had to reference OrderID:
public static bool orderVerify(DropDownList ddlProductID, string orderID) 

Open in new window


Finally I had to add the OrderID.Text reference:
clsDataLayer.orderVerify(ddlProductID, orderID.Text);

Open in new window




Thanks for your help.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Creating and Managing Databases with phpMyAdmin in cPanel.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

13 Experts available now in Live!

Get 1:1 Help Now