Solved

List box not populating based on MySQL query

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

Technology Partners: 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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 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