using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class cp : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
SqlCommand cmd = new SqlCommand("select * from users", con);
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string eid = reader["ElectionId"].ToString();
string pwd = reader["Password"].ToString();
if (eid == TextBox1.Text && pwd == TextBox2.Text)
{
SqlCommand cmd2 = new SqlCommand("UPDATE [users] SET [Password] ='"+TextBox3.Text +"' WHERE [ElectionId] =" + "'" + TextBox1.Text + "'", con);
cmd2.ExecuteNonQuery();
}
else
{
string script = "window.onload = function() { alert('Invald Entry'); }";
ClientScript.RegisterStartupScript(this.GetType(), "alert", script, true);
}
}
con.Close();
}
}
the above code is giving the follwing error
There is already an open DataReader associated with this Command which must be closed first.
Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
please tell the changes that must be made in the above code to eliminate the error.