i am using visual studio for making website using c#
an error is occuring "There is already an open DataReader associated with this Command which must be closed"
the code is
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Getregioncategory();
}
public void Getregioncategory()
{
DataTable dt = new DataTable();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("TMS_GetRegion", conn);
cmd.CommandType = CommandType.StoredProcedure;
try
{
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
this.gvwregioncategory.DataSource = cmd.ExecuteReader();
this.gvwregioncategory.DataBind();
}
}
catch (Exception ex)
{
string msg = ex.Message;
Response.Write(msg);
Response.End();
}
finally
{
conn.Close();
cmd.Dispose();
}
}
}
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvwregioncategory" runat="server" AutoGenerateColumns="False" CssClass="basix" AllowPaging="True" >
<columns>
<asp:BoundField DataField="Region" HeaderText="region" />
<asp:BoundField DataField="Regionid" HeaderText="region_id" />
</columns>
</asp:GridView>
<asp:label ID="lblStatus" runat="server"></asp:label>
</div>
</form>