Hi
I have a login Page where i want the Faculty to login and on the next page which is "Welcome_Faculty" i want to display a label showing " Welcome Faculty_Name" from the below table in Sql server.The Table is shown below.
Faculty_Name UserName Password
Elena Popel epopel popel
Raied Salman rsalman salman
Ravi Rathnam rrathnam rathnam
the code which i have for Login page is as follows
public partial class Faculty_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnLogin_Click(object sender, EventArgs e)
{
string strcon = ConfigurationManager.ConnectionStrings["MyDatabaseConnection"].ConnectionString;
SqlConnection con = new SqlConnection(strcon);
SqlCommand com = new SqlCommand("CheckFaculty", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("username", TextBox1.Text);
SqlParameter p2 = new SqlParameter("password", TextBox2.Text);
com.Parameters.Add(p1);
com.Parameters.Add(p2);
con.Open();
SqlDataReader rd = com.ExecuteReader();
if (rd.HasRows)
{
rd.Read();
Session["username"]= TextBox1.Text;
// Label5.Text = "Login successful.";
Response.Redirect("Welcome_Faculty.aspx");
}
else
{
Label5.Text = "Invalid username or password.";
}
}
}
The login page is Working perfect but when i go on the next page i want to display a label which picks the faculty_name from the above table corresponding to the username and password .How can i do that
Can somebody help me with this?
Kiresh GangariyaPosted Dec 1, 2012, 3:38 AM
int columnIndex = thisReader.GetOrdinal("ColumnName");
string FacultyName= thisReader.GetString(columnIndex);
Session["FacultyName"]= FacultyName;
naman kaushalPosted Dec 3, 2012, 5:54 PM
Thanks it worked for me.
naman kaushalPosted Dec 3, 2012, 5:54 PM
Thanks it worked for me.
naman kaushalPosted Dec 3, 2012, 5:37 PM
Thanks for the reply but i want to pick up the Faculty_Name from the table not the UserName
naman kaushalPosted Dec 3, 2012, 5:36 PM
Thanks for the reply but i want to pick up the Faculty_Name from the table not the UserName
Satyapriya NayakPosted Dec 1, 2012, 12:31 AM
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;
using System.Data.SqlClient;
namespace Login_Page_Using_Stored_Procedure
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlParameter UserName, Password;
protected void btn_login_Click(object sender, EventArgs e)
{
UserName = new SqlParameter();
Password = new SqlParameter();
SqlConnection con = new SqlConnection(strConnString);
com=new SqlCommand();
com.Connection = con;
con.Open();
Session["UserName"] = TextBox_user_name.Text;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "login_pro";
UserName.SqlDbType = SqlDbType.VarChar;
UserName.Size = 50;
UserName.ParameterName = "@UserName";
UserName.Value = TextBox_user_name.Text.ToString();
UserName.Direction = ParameterDirection.Input;
Password.SqlDbType = SqlDbType.VarChar;
Password.Size = 50;
Password.ParameterName = "@Password";
Password.Value = TextBox_password.Text.ToString();
Password.Direction = ParameterDirection.Input;
com.Parameters.Add(UserName);
com.Parameters.Add(Password);
int status;
status = Convert.ToInt16(com.ExecuteScalar());
if (status == 1)
{
Response.Redirect("Welcome.aspx");
}
else
{
lblmessage.Text = "Invalid UserName and Password...";
}
con.Close();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Welcome.aspx.cs" Inherits="Login_Page_Using_Stored_Procedure.Welcome" %>
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;
namespace Login_Page_Using_Stored_Procedure
{
public partial class Welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "WELLCOME :: " + Session["UserName"];
}
}
}
Vishnujeet KumarPosted Nov 30, 2012, 11:37 PM
lblfaculty.Text = "Welcome : " + Session["username"];
try below link,
http://www.devmanuals.com/tutorials/ms/aspdotnet/login.html