Solved

List box not populating based on MySQL query

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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