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

Satish Raykar2 reputationPosted Sep 17, 2009, 3:32 AM EDT
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();
}
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Sep 17, 2009, 3:34 AM EDT
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");
}
roy himanshu98 reputationPosted Sep 17, 2009, 3:56 AM EDT
thanx
Master BillaRank #2,229 · 630 reputationPosted Sep 17, 2009, 8:06 AM EDT
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