Anda di halaman 1dari 2

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;
using System.Data;

namespace manish
{
public partial class WebForm1 : System.Web.UI.Page
{

protected void Button1_Click(object sender, EventArgs e)


{

DataTable dt = new DataTable();


SqlDataAdapter adp = new SqlDataAdapter();
try
{

SqlConnection con = new


SqlConnection(ConfigurationManager.ConnectionStrings["COnnectionString"].Connection
String);
SqlCommand cmd = new SqlCommand("select * from login where
adminid=@adminid and password=@password", con);
//Checking for registerd adminid and password
cmd.Parameters.AddWithValue("@adminid", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@password", TextBox2.Text.Trim());
adp.SelectCommand = cmd;
adp.Fill(dt);
cmd.Dispose();

if (dt.Rows.Count > 0)
{
Response.Write("Login Successfull");
Response.Redirect("Student_Details.aspx");
//we can show messagebox using
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Login
Successfull');", true);

}
else

{
ScriptManager.RegisterStartupScript(this, this.GetType(),
"Message", "alert('Wrong Username/Password');", true);
TextBox1.Text = "";
TextBox2.Text = "";

//Or write using Response.Write("Wrong Username/Password");


//Response.Write("Wrong Username/Password");
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(),
"Message", "alert('Oops!! following error occured : " + ex.Message.ToString() +
"');", true);
// Response.Write("Oops!! following error occured: "
+ex.Message.ToString());
}
finally
{
dt.Clear();
dt.Dispose();
adp.Dispose();
}
}

protected void Page_Load(object sender, EventArgs e)


{
TextBox1.Focus();
}

protected void Button2_Click(object sender, EventArgs e)


{
TextBox1.Text = "";
TextBox2.Text = "";
}
}
}

Anda mungkin juga menyukai