Hi,
I am beginner to Windows Applications. I populate all the company names in one combobox ,If i select one company name then thier invoiceno,orderno,customer address,ondate,invoicedate will automatically display in their respective textboxes from database.for that i wrote the code like this.it displays only customer address only remaining it wont display.like orderno,invoiceno,ondate,invoicedate etc..please do the needful.
private void loadcompanies()
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand(""select t2.compaddress,t1.invoiceno,t1.orderno,t1.ondate,t1.particulars,t1.perprice,t1.amount,t2.netvat,t2.tamount,t2.netamount from tbl_report2 t2,tbl_report1 t1 where t1.compname=@compname and t2.compname=@compname", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
if (con.State == ConnectionState.Closed)
{
con.Open();
}
da.Fill(dt);
cmb_companyname.DataSource = dt;
cmb_companyname.DisplayMember = "compname";
cmb_companyname.ValueMember = "compaddress";
}
private void cmb_companyname_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select t2.compaddress,t1.invoiceno,t1.orderno,t1.ondate,t1.particulars,t1.perprice,t1.amount,t2.netvat,t2.tamount,t2.netamount from tbl_report2 t2,tbl_report1 t1 where t1.compname='hdfcbank' and t2.compname='hdfcbank'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
txt_customeraddress .Text =dt .Rows [0][0].ToString ();
txt_customeraddress.Text = dt.Rows[0][0].ToString();
txt_invoiceno.Text = dt.Rows[0][0].ToString();
txt_orderno.Text = dt.Rows[0][0].ToString();
txt_ondate.Text = dt.Rows[0][0].ToString();
cmb_particulars.Text = dt.Rows[0][0].ToString();
txt_quantity.Text = dt.Rows[0][0].ToString();
txt_perprice.Text = dt.Rows[0][0].ToString();
txt_amount.Text = dt.Rows[0][0].ToString();
txt_vat.Text = dt.Rows[0][0].ToString();
txt_totalamount.Text = dt.Rows[0][0].ToString();
txt_netamount.Text = dt.Rows[0][0].ToString();
}
}
Best,
Sudheep.