Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 3 webforms admin,student,teacher. i want to display details of only that user who has logged in.But it is not displaying anything.Also there is no error.I can not find what is the problem. i have written following code.please help.


C#
protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Session["name"].ToString();
            
            detail();
        }
        public void detail()
        {
            SqlConnection conn = new SqlConnection("Data Source=SNEHAL-PC\\SNEHAL1;Initial Catalog=TEMPRUJU;Integrated Security=True");
            SqlCommand cmd;
            conn.Open();
            //String st = "select name,midname,surname,contact,dob,email,address,ltype,image from login";
            
            cmd = new SqlCommand("select Id,name,midname,surname,username,password,contact,dob,email,address,ltype,image from login where id='" + User.Identity.Name + "'", conn);
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlDataAdapter ad = new SqlDataAdapter(cmd);

            ad.Fill(ds);

            GridView2.DataSource = ds;

            GridView2.DataBind();
            conn.Close();
        }
Posted
Updated 14-Feb-14 2:10am
v2
Comments
Dinesh.V.Kumar 14-Feb-14 8:57am    
Are you sure this query returns the data you need to display..
"select Id,name,midname,surname,username,password,contact,dob,email,address,ltype,image from login where id='" + User.Identity.Name + "'", ?????
Member 10523130 14-Feb-14 9:34am    
no.the problem is in where condition but i dont know what else will be the code for where condition
Dinesh.V.Kumar 14-Feb-14 9:37am    
Check the value for this "User.Identity.Name"...
MK-Gii 14-Feb-14 9:00am    
Can you check if your SQLconnection is open?
if (conn.State != System.Data.ConnectionState.Open)
{ throw new Exception("Connection is not open!"); }
Also - please try to debug - check what is being assigned to "User.Identity.Name".
ahmedfaruk88 16-Feb-14 17:38pm    
Check to make sure that you have records in your table. Secondly check the id of the WHERE clause and id of the SELECT statement. Thirdly put your code in a try... catch block, then display the exception thrown if any on the screen

1 solution

At first check query formulated in your code on database using management studio.i think there should be any blank space is attached with your field in your code or in data base field for name. & it will be better if you use Identity id instead of Identity name.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900