When I execute this SELECT query directly, it works. However, while debugging, I see my dataset is empty. What can the issue possibly be?
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");
}
}
}
I am following this tutorial.