I'm new here and new at C# programming.
I need code that will fill combobox from database.
I made something like this, but this doesn't work:
private void comboCategory_SelectedIndexChanged(object sender, EventArgs e)
{
comboCategory.Items.Clear();
string SQLcombo = "SELECT CategoryName AS ComboList FROM Category";
SqlCommand cmdCombo = new SqlCommand(SQLcombo, cnnStore);
cnnStore.Open();
SqlDataReader comboReader;
comboReader = cmdCombo.ExecuteReader();
while (comboReader.Read())
{
comboCategory.Items.Add("CategoryList");
}
}
And when item from combo is selected, it need to show data from database in textbox. (ID, Name and Description)

Any help is apriciated!!
ThX


Sign In
Create Account

Back to top









