简体   繁体   中英

binding of data to dropdownlist getting error of invalid object name in asp.net

SqlDataAdapter da = new SqlDataAdapter("select * from state1",con);
DataSet ds = new DataSet();
da.Fill(ds,"state1");------------getting error in this line like invalid object name,satate1
ddlstate.DataSource = ds;
ddlstate.DataTextField = "sname";
ddlstate.DataValueField = "sid" ;
ddlstate.DataBind();

I think the error is "object name,state1" in which case the error is being thrown from your database because it can't find a table or view called state1. Please check that you are connecting to the correct database or if your table is in another schema apart from dbo, that you use the schema qualified name eg schemaname.state1

I think this may be the problem:

SqlDataAdapter da = new SqlDataAdapter("select * from state1",con);
DataSet ds = new DataSet();
da.Fill(ds,"state1");
ddlstate.DataSource = ds;//------------------> I think this one is worng. It should be table i.e. ds.Tables[0]/ds.Tables["state1"] if "ds" is not null.
ddlstate.DataTextField = "sname";
ddlstate.DataValueField = "sid" ;
ddlstate.DataBind();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM