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(); } }
select CAST(RTRIM(location_name) AS VARCHAR(50)) from dbo.Location
select location_name from dbo.Location where isnull(location_name ,'')<>''
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)