This is what I want: A method that is within a class that will return iteratively the values of a certain column. This values will the be added to a combobox when the method is invoked. Here is my attempt:
public string FillCombo()
{
string connstring = "Data Source=HP\\SQLEXPRESS;Initial Catalog=Arana;Integrated Security=True";
string query = "Select * from categorias";
SqlConnection conn = new SqlConnection(connstring);
SqlCommand command = new SqlCommand(query, conn);
SqlDataReader read;
conn.Open();
read = command.ExecuteReader();
while (read.Read())
{
string combodata = read.GetString(1);
return (combodata);
}
return null;
}
however, when this method is invoked, it only returns the first row into de combobox, not the other values.
List<string>or something similar.returnin yourwhileloop which willreturnfrom the method, you could add each data value to a collection outside of your method.