How do I retrieve data from DataSet to ListBox?

advertisements

All I am getting is the empty listBox while retrieving data from DataSet. Heres the code:

DataSet dt_product = dBCommand.ExecuteNonQuery("SELECT * FROM PRODUCT");

listBx_prod.DataSource=dt_product.Tables[0].Columns[1].ExtendedProperties.Cast<DataRow>().ToList();

I debugged and my DataSet successfully retrieves data from Database. Where am I wrong?


I must admit that i don't know why you are trying to read the PropertyCollection from the second DataColumn in your first table of the DataSet via ExtendedProperties at all.

But since you've mentioned that you just want to show the data in the ListBox:

listBx_prod.DataSource = dt_product.Tables[0];
listBx_prod.DisplayMember = "ProductName";
listBx_prod.ValueMember = "ProductId";