Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- using MySql.Data.MySqlClient;
- namespace WindowsFormsApplication1 {
- public partial class Form1 : Form {
- private static string connStr = "server=localhost;user=root;database=winestore;port=3306;";
- private static MySqlConnection connection = new MySqlConnection(connStr);
- public Form1() {
- try {
- InitializeComponent();
- connection.Open();
- MySqlDataAdapter adapter = new MySqlDataAdapter();
- DataSet ds = new DataSet();
- string commandText = "SELECT winery_id, winery_name FROM winery ORDER BY winery_name ASC;";
- adapter.SelectCommand = new MySqlCommand(commandText, connection);
- adapter.Fill(ds, "winery_name");
- comboBox1.ValueMember = "winery_id";
- comboBox1.DisplayMember = "winery_name";
- comboBox1.DataSource = ds.Tables["winery_name"];
- } catch (Exception ex) {
- MessageBox.Show(ex.ToString());
- }
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
- MySqlDataAdapter adapter = new MySqlDataAdapter();
- DataTable table = new DataTable();
- string commandText = "SELECT wine_name, year FROM wine WHERE winery_id='" + comboBox1.SelectedValue + "';";
- adapter.SelectCommand = new MySqlCommand(commandText, connection);
- adapter.Fill(table);
- dataGridView1.DataSource = table;
- dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement