Item_Code Item_Name Item_Make Item_Price UnitofMeasurement Cable anchor 45.0000 meter Cable polycab 30.0000 meter Button anchor 15.0000 unit Button havells 20.0000 unit Switch cona 70.0000 unit
private void comboBoxName_SelectedIndexChanged(object sender, EventArgs e) { if (!string.IsNullOrEmpty(comboBoxName.Text)) { fillMake(); comboBoxMake.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() { using (SqlConnection con = new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True")) { string str = "Select Item_Make from Item Where Item_Name=@Item_Name"; 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.ValueMember = "Item_Make"; comboBoxMake.DisplayMember = "Item_Make"; comboBoxMake.DataSource = dtItem; } } } }
cmd.Parameters.AddWithValue("@Item_Name",comboBoxName.Text);
cmd.Parameters.AddWithValue("@Item_Name",comboBoxName.Selecteditem.Tostring());
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)