【发布时间】:2014-05-13 15:19:02
【问题描述】:
当我直接执行这个 SELECT 查询时,它可以工作。但是,在调试时,我看到我的数据集是空的。可能是什么问题?
protected void Grid_ItemList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Connection con = new Connection();
con.con = new SqlConnection(con.str);
try
{
con.con.Open();
con.cmd = new SqlCommand("Select Item_Code,Item_Name from Pharmacy_Item_M", con.con);
var ddl = (DropDownList)e.Row.FindControl("ddlnames");
SqlDataAdapter da = new SqlDataAdapter(con.cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.con.Close();
ddl.DataSource = ds;
ddl.DataTextField = "ItemName";
ddl.DataValueField = "ItemCode";
ddl.DataBind();
}
catch (Exception ex)
{
log.Warn("Unable to open connection");
}
}
}
我正在关注this 教程。
【问题讨论】:
-
你有什么异常吗?
-
ItemName & ItemCode 应该是 Item_Name & Item_Code 吧?
-
@RajeevKumar 没有例外。填充数据集后它只是空的。
-
@markpsmith 是的。但是在它到达那里之前它是空的。
-
@sna2stha con.str 正在从我的连接对象中提取连接字符串。这是完美的填充。