Solved

List box not populating based on MySQL query

Posted on 2015-02-17
2
107 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

28 Experts available now in Live!

Get 1:1 Help Now