combobox textbox Items price sss 100 ddd 140 fff 220
private void Form4_Load(object sender, EventArgs e) { con = new SqlConnection("data source=PC\\SQLEXPRESS;integrated security=true;Initial catalog=MyDB"); BindData1(); } public void BindData1() { con.Open(); string strCmd = "select Items from tblbill"; SqlCommand cmd = new SqlCommand(strCmd, con); SqlDataAdapter da = new SqlDataAdapter(strCmd, con); DataSet ds = new DataSet(); da.Fill(ds); cmd.ExecuteNonQuery(); con.Close(); comboBox1.DisplayMember = "items"; comboBox1.ValueMember = "items"; comboBox1.DataSource = ds.Tables[0]; comboBox1.Enabled = true; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { con.Open(); string sel = comboBox1.SelectedItem.ToString(); SqlCommand cmd = new SqlCommand("select price from tblbill where items=" + comboBox1.SelectedValue, con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { p = dr[0] as string; //department = reader[1] as string; } textBox1.Text = p; con.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)