What Was Error in My code Of C# page?
for above the requirement i made the code like these its also working well .
protected void Page_Load(object sender, EventArgs e)
{
string us = Session["username"].ToString();
if(us!=null)
{
Label1.Text= us.ToString();
Label1.ForeColor = System.Drawing.Color.BlueViolet;
Label1.Font.Bold = true;
}
//string uname = Session["username"].ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("ju", conn);
cmd.Parameters.AddWithValue("@username", us);
//cmd.Parameters.AddWithValue("@pwd", SqlDbType.VarChar(20).Value);
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TxtFNme.Text = dr["fst_name"].ToString();
TxtLNme.Text = dr["lst_name"].ToString();
Txtage.Text = dr["AGE"].ToString();
TxtGen.Text = dr["Gender"].ToString();
TxtDesig.Text = dr["designation"].ToString();
TxtRepto.Text = dr["Reporting_to"].ToString();
TxtLctn.Text = dr["location"].ToString();
DropDownList1.Text = dr["costcenter_id"].ToString();
DropDownList2.Text = dr["proof_type_id"].ToString();
}
dr.Close();
// Label1.Text = Session["username"].ToString();
conn.Close();
}
friends i ve different username like eexample
1)ram
2)david
3)kumar
above the code always display ram details oly... when i try logged on sum other users also deafult showing ram details only.
do The need full.
Rocky RockyPosted Jun 28, 2013, 1:31 AM
(
@username varchar(20)
)
as
begin
declare @usercode varchar(20),
@reporting varchar(20)
select @usercode=user_id,@reporting=reporting_to from users where username=@username begin
if exists(select * from users where user_id=@usercode)
select
fst_name,
lst_name,
DATEDIFF(yy,CONVERT(DATETIME, DOB),GETDATE()) AS AGE,
case gender when 'M' then 'Male' when 'F' then 'Female' end as Gender,
designation,
departments,
location,
proof_type_id,
costcenter_id,
( reporting_to +' '+ (select b.fst_name+' '+b.lst_name from users a inner join users b on a.reporting_to=b.user_id where a.reporting_to=@reporting ))reporting_to
from
users
where username=@username and user_id=@usercode
end
end
Sanjeeb LenkaPosted Jun 28, 2013, 1:13 AM