private void Purchase_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'supplierDataSet.Supplier' table. You can move, or remove it, as needed. this.supplierTableAdapter.Fill(this.supplierDataSet.Supplier); fillName(); comboBoxName.SelectedIndex = -1; } private void fillName() { string str = "Select distinct Item_Name from Item"; using (SqlConnection con = new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True")) { using (SqlCommand cmd = new SqlCommand(str, con)) { using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { DataTable dtItem = new DataTable(); adp.Fill(dtItem); comboBoxName.DataSource = dtItem; comboBoxName.DisplayMember = "Item_Name"; comboBoxName.ValueMember = "Item_Name"; } } } } private void fillMake() { string str = "Select Item_Make from Item Where Item_Name=@Item_Name"; using (SqlConnection con = new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True")) { using (SqlCommand cmd = new SqlCommand(str, con)) { cmd.Parameters.AddWithValue("@Item_Name", comboBoxName.Text); using (SqlDataAdapter adp = new SqlDataAdapter(cmd)) { DataTable dtItem = new DataTable(); adp.Fill(dtItem); comboBoxMake.DataSource = dtItem; comboBoxMake.ValueMember = "Item_Make"; comboBoxMake.DisplayMember = "Item_Make"; } } } } private void comboBoxName_SelectedIndexChanged_1(object sender, EventArgs e) { if (!string.IsNullOrEmpty(comboBoxName.Text)) { comboBoxMake.Enabled = true; fillMake(); comboBoxMake.SelectedIndex = -1; } } private void comboBoxMake_SelectedIndexChanged_1(object sender, EventArgs e) { if (!string.IsNullOrEmpty(comboBoxMake.Text)) { textBoxPrice.Enabled = true; textBoxUoM.Enabled = true; } SqlConnection con = new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True"); SqlCommand cmd = new SqlCommand("Select * from Item Where Item_Make='" + comboBoxMake.Text + "' AND Item_Name='" + comboBoxName.Text + "'", con); SqlDataReader reader; try { if (con.State == ConnectionState.Closed) { con.Open(); } reader = cmd.ExecuteReader(); while (reader.Read()) { textBoxPrice.Text = Convert.ToString(reader["Price"]); textBoxUoM.Text = Convert.ToString(reader["Unit"]); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (con.State == ConnectionState.Open) { con.Close(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)