Hello,
Please help!!!
I am working in C#.I have a form that a combo box and Three Text box.The combo box contains Item codes. when i select a item code in combo box then related data (Item Name,price,Quantity) is displayed in three text boxes.But i get only one value in textboxs. plz solve my problem.My code past here.
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string s;
s = comboBox2.ToString();
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
SqlCommand cmd=new SqlCommand ("select column003,column005,column007 from CATABLE004 where column002='" + s + "'",cn);
da2 = new SqlDataAdapter();
ds = new DataSet();
cmd.Connection = cn;
da2.SelectCommand = cmd;
da2.Fill(ds, "CATABLE004");
textBox2.Text = comboBox2.SelectedValue.ToString();
textBox3.Text = comboBox2.SelectedValue.ToString();
}
Loading
Master BillaPosted Sep 17, 2009, 12:06 PM
Your code liek this way
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string s;
s = comboBox2.SelectedItem.Text;
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
SqlCommand cmd=new SqlCommand ("select column003,column005,column007 from CATABLE004 where column002='" + s + "'",cn);
da2 = new SqlDataAdapter();
ds = new DataSet();
cmd.Connection = cn;
da2.SelectCommand = cmd;
da2.Fill(ds);
if(da2.Table[0].Rows.Count==1)
{
textBox1.Text = ds.table[0].rows[0].item["column003"].ToString();
textBox2.Text = ds.table[0].rows[0].item["column005"].ToString();
textBox3.Text = ds.table[0].rows[0].item["column007"].ToString();
}
}
Thank you
roy himanshuPosted Sep 17, 2009, 7:56 AM
thanx
Hirendra SisodiyaPosted Sep 17, 2009, 7:34 AM
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
string s;
s = comboBox2.ToString();
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
SqlCommand cmd=new SqlCommand ("select column003,column005,column007 from CATABLE004 where column002='" + s + "'",cn);
da2 = new SqlDataAdapter();
ds = new DataSet();
cmd.Connection = cn;
da2.SelectCommand = cmd;
da2.Fill(ds, "CATABLE004");
textBox2.Text = ds.table(0).rows(0).item("column005");
textBox3.Text = ds.table(0).rows(0).item("column007");
}
Satish RaykarPosted Sep 17, 2009, 7:32 AM
After creating dataset, create datareader and from the datareader extract the three values and assign iy to the Textboxes.
Ex:
DataTableReader DR = da2.Tables["tablename"].CreateDataReader();
while (DR.Read())
{
textbox1.text=DR["column1"].tostring();
textbox2.text=DR["column2"].tostring();
textbox3.text=DR["column3"].tostring();
}