saifullah khan

saifullah khan

  • NA
  • 335
  • 300.3k

Invalid column name ''.

Jun 4 2011 1:50 AM
i have 3 database tables.
1. town(townname)
2.phase(phasename,townname)
3.sector(sectorname,townnam,phasename)
the datatype of all these fields is nvchar(50).

i have one webform sectorname.aspx
it consists:
townname.dropdown
phasename.dropdown
sectorname.textbox

townname.dropdown takes data frm town table in the database.
when i click on on townname.dropdown and select an item. it takes all those phase name in phase table that come under that selected town. but when i select townname it gives me the following error.

Invalid column name 'hayatabad'.


the code the given here.

protected void TownID_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataSet ds = new DataSet();
SqlDataAdapter adap = new SqlDataAdapter();


cmd = new SqlCommand("select * from Phase where TownName=" + TownName.SelectedValue.ToString(), con);
//cmd.Connection = con;
con.Open();

adap.SelectCommand = cmd;
adap.Fill(ds);
dt = ds.Tables[0];
PhasName.DataSource = dt;
PhasName.DataTextField = "PhaseName";
PhasName.DataValueField = "PhaseName";
PhasName.DataBind();

}

please tell me whats the problem.???

Answers (6)