如何在网格视图中显示特定记录 [英] how to display specific record in grid view

查看:90
本文介绍了如何在网格视图中显示特定记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个webforms管理员,学生,老师。我想只显示已登录用户的详细信息。但它没有显示任何内容。也没有错误。我找不到问题所在。我写了以下代码。请帮助。





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.


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();
        }

推荐答案

首先使用management studio查看在数据库代码中制定的查询。我认为应该有任何空白空间附加在代码中的字段或名称的数据库字段中。如果您使用身份ID而不是身份名称会更好。
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.


这篇关于如何在网格视图中显示特定记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆