create an app_code
create two folders in it first folder named as business logic layer and second as data logic layer
create a class in each folders
under business logic layer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
public class database
{
public database()
{
}
public int Load_Redirect()
{
businesslogic obj = new businesslogic();
try
{
switch ((int)obj.Load().Rows[0][0])
{
case 1:
return 1;
case 2:
return 2;
case 3:
return 3;
default:
return 0;
}
}
catch (IndexOutOfRangeException ex)
{
return 0;
}
finally
{
obj = null;
}
}
}
under data logic layer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI;
public class businesslogic
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True");
public businesslogic()
{
con.Open();
}
public DataTable Load()
{
Page page = (Page)HttpContext.Current.Handler;
TextBox tb1 = (TextBox)page.FindControl("TextBox1");
TextBox tb2 = (TextBox)page.FindControl("TextBox2");
string sql = string.Format("select r.rid from employee e inner join specification1 r on r.eid =e.eid where uname='" + tb1.Text + "' and password='" + tb2.Text + "'");
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sql,con);
try
{
da.Fill(ds, "d");
return ds.Tables["d"];
}
catch (SqlException ex)
{
throw;
}
finally
{
ds.Dispose();
da.Dispose();
con.Close();
con.Dispose();
}
}
}
in ur default page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="uname"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="pass"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="submit" onclick="Button1_Click" />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
c#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
database obj = new database();
if((int)obj.Load_Redirect()==1)
Response.Redirect("admin.aspx");
else if((int)obj.Load_Redirect()==2)
Response.Redirect("super.aspx");
else if ((int)obj.Load_Redirect()==3)
Response.Redirect("user.aspx");
else
Label3.Text="missmatch";
}
}