Hi,
it shows this kind of error.in my coding.please do the needful.
Error:Ambiguous column name 'compname'
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.quantity,t1.perprice,t1.amount,t2.netvat,t2.tamount,t2.netamount from tbl_report2 t2,tbl_report1 t1 where t1.invoiceno= t2.invoiceno and t2.compname=t1.compname AND compname ='hdfcbank'",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 = "compname";
}
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.quantity,t1.perprice,t1.amount,t2.netvat,t2.tamount,t2.netamount from tbl_report2 t2,tbl_report1 t1 where t1.invoiceno= t2.invoiceno and t2.compname=t1.compname AND compname ='hdfcbank'", con);
//SqlCommand cmd = new SqlCommand("select custaddress from tbl_customer where custname=@custname", con);
cmd.Parameters.AddWithValue("@custname",cmb_companyname .Text );
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
//txt_customeraddress.Text = cmb_companyname.SelectedValue.ToString();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
txt_customeraddress .Text =dt .Rows [0][0].ToString ();
txt_customeraddress.Text = dt.Rows[0]["compaddress"].ToString();
txt_invoiceno.Text = dt.Rows[0]["invoiceno"].ToString();
txt_orderno.Text = dt.Rows[0]["orderno"].ToString();
txt_ondate.Text = dt.Rows[0]["ondate"].ToString();
cmb_particulars.Text = dt.Rows[0]["particulars"].ToString();
txt_quantity.Text = dt.Rows[0]["quantity"].ToString();
txt_perprice.Text = dt.Rows[0]["perprice"].ToString();
txt_amount.Text = dt.Rows[0]["amount"].ToString();
txt_vat.Text = dt.Rows[0]["netvat"].ToString();
txt_totalamount.Text = dt.Rows[0]["tamount"].ToString();
txt_netamount.Text = dt.Rows[0]["netamount"].ToString();
}
}
Best,
Sudheep.