Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ADODatabases {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window {
- public MainWindow() {
- InitializeComponent();
- }
- private void Window_Loaded(object sender, RoutedEventArgs e) {
- string connStr = @"Data Source=hansen-laptop\SQLEXPRESS;
- database=Northwind;Integrated Security=True";
- SqlConnection con = new SqlConnection(connStr);
- string sql = "SELECT distinct country FROM customers";
- SqlCommand cmd = new SqlCommand(sql, con);
- con.Open();
- SqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read()) {
- string line ="" + reader[0];
- comboBox1.Items.Add(line);
- }
- con.Close();
- }
- private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) {
- string connStr = @"Data Source=hansen-laptop\SQLEXPRESS;
- database=Northwind;Integrated Security=True";
- SqlConnection con = new SqlConnection(connStr);
- string sql = "SELECT ContactName, City FROM customers WHERE country=@country";
- SqlCommand cmd = new SqlCommand(sql, con);
- cmd.Parameters.AddWithValue("@country", comboBox1.SelectedValue.ToString());
- con.Open();
- SqlDataReader reader = cmd.ExecuteReader();
- listBox1.Items.Clear();
- while (reader.Read()) {
- string line = "" + reader[0];
- listBox1.Items.Add(line);
- }
- con.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement