sir in the below code for every correct eid and password it is executing the else statement(i.e.; it is showing invalid entry)
please tel the necessary changes required
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)
{
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string eid = "";
string pwd = "";
SqlCommand cmd = new SqlCommand("select * from users", con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
eid = reader["ElectionId"].ToString();
pwd = reader["Password"].ToString();
}
con.Close();
if (eid == TextBox1.Text && pwd == TextBox2.Text)
{
SqlCommand cmd2 = new SqlCommand("UPDATE [users] SET [Password] ='" + TextBox3.Text + "' WHERE [ElectionId] =" + "'" + TextBox1.Text + "'", con);
con.Open();
cmd2.ExecuteNonQuery();
con.Close();
Response.Redirect("cpr.aspx");
}
else
{
string script = "window.onload = function() { alert('Invald Entry'); }";
ClientScript.RegisterStartupScript(this.GetType(), "alert", script, true);
}
}
}