Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I populate a listbox using select query (which stems from a combobox)

If 'multi ice cream' is selected in the combobox then I want the system to select that row and show me what is in the 'process' column in my listbox

so based on what the user select from the comboBox, you make a query and fill the ListBox with the result

So far the code is not returning anything, I'm not too sure why

MAcon.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select Process from [Product Family] Where [Product Name] = @ProductName", MAcon);
da.SelectCommand.Parameters.AddWithValue("@Process", ItemCBx.SelectedItem.ToString());
DataTable dtbl = new DataTable();
da.Fill(dtbl);

if (dtbl.Rows.Count == 1)
{
    Listbox1.Items.Add(dtbl.Rows[0][0]);
}

MAcon.Close();


What I have tried:

MAcon.Open();
OleDbCommand da = new OleDbCommand("Select Process from [Product Family] Where [Product Name] = @ProductName", MAcon);
OleDbDataReader sdr = da.ExecuteReader();
while (sdr.Read())
{
    Console.WriteLine(sdr[0].ToString());
}
MAcon.Close();
Posted
Updated 17-May-18 20:00pm
v6

"Hard code" the query first; and get that to work.

THEN start obfusticating by using inline variables, removing intermediate variables, etc.

In other words, make it as difficult to debug as possible AFTER it is working.
 
Share this answer
 
Where [Product Name] = @ProductName"

but
Parameters.AddWithValue("@Process",


Change the second to be @ProductName.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900