Robin Harris
asked on
List box not populating based on MySQL query
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.
"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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Open in new window
I also had to reference OrderID:
Open in new window
Finally I had to add the OrderID.Text reference:
Open in new window
Thanks for your help.