public Form1() { InitializeComponent(); string Sql = "SELECT [Lot ID] from LotID"; SqlConnection conn = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=Car Dealership;Integrated Security=True"); conn.Open(); SqlCommand cmd = new SqlCommand(Sql, conn); SqlDataReader DR = cmd.ExecuteReader(); while (DR.Read()) { dealerTxtBox.Items.Add(DR[0]); LotFilterTB.Items.Add(DR[0]); } this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick); //Getting list of models for combobox Sql = "SELECT [Make] from MakeModelID"; conn = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=Car Dealership;Integrated Security=True"); conn.Open(); cmd = new SqlCommand(Sql, conn); DR = cmd.ExecuteReader(); while (DR.Read()) { if (!makeTxtBox.Items.Contains(DR[0])) { makeTxtBox.Items.Add(DR[0]); } } //Getting list of Colors for combobox Sql = "SELECT [Color] from ColorID"; conn = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=Car Dealership;Integrated Security=True"); conn.Open(); cmd = new SqlCommand(Sql, conn); DR = cmd.ExecuteReader(); while (DR.Read()) { ColorComboBox.Items.Add(DR[0]); } //Hiding Stuff FilterLabel.Hide(); LotFilterTB.Hide(); }
private void GetCars_Click(object sender, EventArgs e) { FilterLabel.Hide(); LotFilterTB.Hide(); con = new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=Car Dealership;Integrated Security=True"); con.Open(); SqlDataAdapter sqlDa = new SqlDataAdapter("Select * FROM CarID", con); DataTable dtbl = new DataTable(); sqlDa.Fill(dtbl); dataGridView1.DataSource = dtbl; con.Close(); }