plz exaplain me how to fetch details of user?
in Sql database have one table in that table they 4 coloumn with usernames and passwords and another table have one username and password details when the program excute time how we will when we will enter the on username and password in the textboxs the will show particular details of that user how it come plz exaplain me
Satyapriya NayakPosted Mar 4, 2013, 9:30 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_related_details
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
string str;
DataTable dt;
int RowCount;
protected void btn_login_Click(object sender, EventArgs e)
{
string UserName = TextBox_user_name.Text.Trim();
string Password = TextBox_password.Text.Trim();
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "Select * from Login";
com = new SqlCommand(str);
sqlda = new SqlDataAdapter(com.CommandText, con);
dt = new DataTable();
sqlda.Fill(dt);
RowCount = dt.Rows.Count;
for (int i = 0; i < RowCount; i++)
{
UserName = dt.Rows[i]["UserName"].ToString();
Password = dt.Rows[i]["Password"].ToString();
if (UserName == TextBox_user_name.Text && Password == TextBox_password.Text)
{
Session["UserName"] = UserName;
Response.Redirect("Details.aspx");
}
else
{
lb1.Text = "Invalid User Name or Password! Please try again!";
}
}
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Details.aspx.cs" Inherits="Login_related_details.Details" %>
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_related_details
{
public partial class Details : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
string s1;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
lb1.Text = "" + "WELLCOME:: " + "" + "" + Session["UserName"] + "";
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select * from Login where UserName='" + Session["UserName"] + "'";
com = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
lbl_UserName.Text = ds.Tables[0].Rows[0]["UserName"].ToString();
lbl_address.Text = ds.Tables[0].Rows[0]["address"].ToString();
lbl_sal.Text = ds.Tables[0].Rows[0]["sal"].ToString();
lbl_phone.Text = ds.Tables[0].Rows[0]["phone"].ToString();
}
}
}