I am creating desktop application in which i have created a form in which there are three comboboxes namely cboproduct,cborawmaterial_id and cborawmaterial.
I have products namely steamiron,mobile,juicer with respective product id.
I have rawmaterials thermostat,inlay,ic,cuplor,jar,led.
I want that when i select one product at a time from cboproduct,i should get its respective rawmaterials in cborawmaterial.
I created a 2 tables
product_info with field product_id and product
rawmaterial_info with field product_id ,rawmaterial_id and rawmaterial
I tried this coding
SqlConnection con;
String message;
con = new SqlConnection(@"Data Source=AKMINDER-PC\SQLEXPRESS;Initial Catalog=elin appliances(Comaker of PHILIPS);Integrated Security=true");
SqlCommand com = new SqlCommand();
message = "Select product_id, product_name from product_info";
con.Open();
DataSet DS = new DataSet();
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = new SqlCommand(message, con);
DA.Fill(DS);
con.Close();
if (DS.Tables[0].Rows.Count > 0)
{
combo1.DataSource = DS.Tables[0];
combo1.DisplayMember = "product_name";
combo1.ValueMember = "product_id";
}
else
{
lblMsg.Text = "No product found";
}
}
private void fillrawmaterialid(string proid)
{
SqlConnection con;
con=new SqlConnection(@"Data Source=AKMINDER-PC\SQLEXPRESS;Initial Catalog=elin appliances(Comaker of PHILIPS);Integrated Security=true");
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "Select Raw_Material_ID ,Raw_Material from Raw_Info where product_id='" + proid + "'";
com.Parameters.AddWithValue("@proid", proid);
DataSet DS = new DataSet();
SqlDataAdapter DA = new SqlDataAdapter();
DA.SelectCommand = com;
con.Open();
DA.Fill(DS);
con.Close();
if (DS.Tables[0].Rows.Count > 0)
{
comborawid.DataSource = DS.Tables[0];
comborawid.DisplayMember = "Raw_Material";
comborawid.ValueMember = "Raw_Material_ID";
}
else
{
lblMsg.Text = "No product found";
}
private void combo1_SelectedIndexChanged(object sender, EventArgs e)
{
string proid=(combo1.SelectedIndex.ToString());
fillrawmaterialid(proid);
}
Now with valuemember and Display member i am getting values in combo1 but i also want the list of raw material corressponding to selected index of Combo1 in cborawmaterial.
e.g if I select Product laptop in combo1_SelectedIndexChanged then only I should get specific raw material related to laptop not all rawmaterials which is stored in database
but i am getting whole list of raw material
do tell me about select query ...what change is need?