Hi,
im have a problem with some code to load data from my MSSQL server in to a combo box. the code works and it loads the data but when i select the item from the drop down it loads all the blank space from the SQL table aswell.
this is my code:
private void loadlocationcombobox()
{
string constr = ConfigurationManager.ConnectionStrings ["SQLServer"].ConnectionString;
string query = "select location_name from dbo.Location";
SqlConnection con = new SqlConnection(constr);
SqlCommand command = new SqlCommand(query, con);
con.Open();
SqlDataReader sqlreader = command.ExecuteReader();
try
{
while (sqlreader.Read())
{
comboLocation.Items.Add(sqlreader[0]);
}
}
catch (Exception ex)
{
MessageBox.Show("A error has occurred: " + ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
sqlreader.Close();
con.Close();
}
}
any help would be great as i have been looking at the code but just cant see how to fix it.