C#至少一个参数没有被指定值
出错在oda.Fill(ds);protectedvoidPage_Load(objectsender,EventArgse){if(!Page.IsPostBack){...
出错在oda.Fill(ds);
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string sqlp = "select * from province";
this.ddlProv.DataSource = DB.GetDS(sqlp);
this.ddlProv.DataTextField = "province";
this.ddlProv.DataValueField = "provinceID";
this.ddlProv.DataBind();
string sqlc = "select * from city where father=" + this.ddlProv.DataValueField;
this.ddlCity.DataSource = DB.GetDS(sqlc);
this.ddlCity.DataTextField = "city";
this.ddlCity.DataValueField = "cityID";
this.ddlCity.DataBind();
string sqla = "select * from area where father=" + this.ddlCity.DataValueField;
this.ddlArea.DataSource = DB.GetDS(sqla);
this.ddlArea.DataTextField = "area";
this.ddlArea.DataValueField = "areaID";
this.ddlArea.DataBind();
}
}
public static DataSet GetDS(string sql)
{
OleDbConnection con = DB.CreateCon();
con.Open();
OleDbDataAdapter oda = new OleDbDataAdapter(sql, con);
DataSet ds = new DataSet();
oda.Fill(ds);
return ds;
}
ddlCity的值(市)是由ddlProv的值(省)所对应的ID确定下来,所以应该是SQL语句错了,不过要怎么改写呢? 展开
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string sqlp = "select * from province";
this.ddlProv.DataSource = DB.GetDS(sqlp);
this.ddlProv.DataTextField = "province";
this.ddlProv.DataValueField = "provinceID";
this.ddlProv.DataBind();
string sqlc = "select * from city where father=" + this.ddlProv.DataValueField;
this.ddlCity.DataSource = DB.GetDS(sqlc);
this.ddlCity.DataTextField = "city";
this.ddlCity.DataValueField = "cityID";
this.ddlCity.DataBind();
string sqla = "select * from area where father=" + this.ddlCity.DataValueField;
this.ddlArea.DataSource = DB.GetDS(sqla);
this.ddlArea.DataTextField = "area";
this.ddlArea.DataValueField = "areaID";
this.ddlArea.DataBind();
}
}
public static DataSet GetDS(string sql)
{
OleDbConnection con = DB.CreateCon();
con.Open();
OleDbDataAdapter oda = new OleDbDataAdapter(sql, con);
DataSet ds = new DataSet();
oda.Fill(ds);
return ds;
}
ddlCity的值(市)是由ddlProv的值(省)所对应的ID确定下来,所以应该是SQL语句错了,不过要怎么改写呢? 展开
4个回答
推荐于2018-03-12
展开全部
sql查询语句,字符型参数需要加单引号限定!
WHERE P.[Ltype]='" + text + "' AND P.[DepID] ='" + u +"' ORDER BY InputTime DESC"
结尾的双引号不要丢!
WHERE P.[Ltype]='" + text + "' AND P.[DepID] ='" + u +"' ORDER BY InputTime DESC"
结尾的双引号不要丢!
展开全部
是你某个方法的实参不对,少了实参或者是类型有问题
出错在oda.Fill(ds);如果ds是个dataset类,你就少加个名称
可以改成oda.Fill(ds, "表名");
出错在oda.Fill(ds);如果ds是个dataset类,你就少加个名称
可以改成oda.Fill(ds, "表名");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是SQL语句有列名或表名写错了,检查下。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有空值,搂主在赋值前作一下检验就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询