void Fillcombo() { string constring = "Data Source=DATABASEHERE;Initial Catalog=HERE;User ID=USERIDHERE;password=PASSWORDHERE"; string Query = "select * from TABLEHERE;"; SqlConnection conDataBase = new SqlConnection(constring); SqlCommand command = new SqlCommand(Query, conDataBase); try { conDataBase.Open(); SqlDataReader myReader = command.ExecuteReader(); while (myReader.Read()) { string lName = myReader["Name"].ToString(); string dirName = myReader["Direction"].ToString(); string midName = myReader["number"].ToString(); comboBox2.Items.Add(lName + " " + dirName + " " + midName); } } catch (Exception ex) { MessageBox.Show(ex.Message); }
private void ComboBox2_SelectedIndexChanged(object sender, EventArgs e) { string constring = "Data Source=DATABASEHERE;Initial Catalog=HERE;User ID=USERIDHERE;password=PASSWORDHERE"; string Query = "select * from TABLEHERE where Name='" + comboBox2.SelectedValue + "'"; SqlConnection conDataBase = new SqlConnection(constring); SqlCommand command = new SqlCommand(Query, conDataBase); try { conDataBase.Open(); SqlDataReader myReader = command.ExecuteReader(); while (myReader.Read()) { string ipName = myReader["ipaddress"].ToString(); textBox1.Text = ipName; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)