如何显示不同登录用户的数据? [英] How to display data of different logged in users?

查看:90
本文介绍了如何显示不同登录用户的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net c#中做一个项目(网站)。我正在使用visual studio 2005和SQL server 2005.我需要知道的是,当学生使用他们的用户名和密码登录时,他们应该从数据库中显示他们的特定信息(如姓名,dob,班级,部门,联系人来自SQL)到不同的网页。我能够只显示一个用户的数据。那么当不同的用户使用他的用户名和密码登录时,如何显示不同的用户数据。



我正在使用两页一页用于登录,另一页用于显示当前用户登录信息。



登录页面代码:



i am doing a project(website) in asp.net c#. I am using visual studio 2005 and SQL server 2005.What I need to know is when a student logs in using their username and password they should have their specific information displayed from the database (like name,dob,class,department, contactno from the SQL) on to a different web page. i am able to display the data for only one user.So how can i display different users data when different user logs in with his username and password.

I am using two pages one for login and other studentinf which displays the information of current user login.

code for login page:

public partial class _Default : System.Web.UI.Page 
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader dr;
SqlDataAdapter da; 

protected void Page_Load(object sender, EventArgs e)
{
    con = new SqlConnection("Data Source=localhost;Initial Catalog=knm;Integrated Security=SSPI");
    con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
    bool temp = false;
    String qry=" Select * from user_login where username='" + TextBox1.Text+"' and password='" +TextBox2.Text+"'";
    cmd=new SqlCommand(qry,con);      
    dr=cmd.ExecuteReader();
    if(dr.Read())
    {
        Label3.Text="Logged in successfull";
        Response.Redirect("studenthome.aspx");
    }

        else
        Label3.Text="invalid user";
    dr.Close(); 
    }

}





studentinf页面代码:





code for studentinf page:

public partial class _Default : System.Web.UI.Page                                                                           
{
   SqlConnection con;
   SqlCommand cmd;
   SqlDataReader dr;
   SqlDataAdapter da;

protected void Page_Load(object sender, EventArgs e)
{
    bool temp = false;
    con = new SqlConnection("Data Source=localhost;Initial Catalog=knm;Integrated Security=SSPI");
    String std = "SELECT* FROM user_login";
    con.Open();
    cmd = new SqlCommand("select * from studentinf ", con);      
    da = new SqlDataAdapter("select * from studentinf ", con);
    DataSet ds = new DataSet();
    da.Fill(ds, "studentinf");
    TextBox1.Text = ds.Tables["studentinf"].Rows[0]["name"].ToString();
    TextBox2.Text = ds.Tables["studentinf"].Rows[0]["dob"].ToString();
    TextBox3.Text = ds.Tables["studentinf"].Rows[0]["class"].ToString();
    TextBox4.Text = ds.Tables["studentinf"].Rows[0]["department"].ToString();
    TextBox5.Text = ds.Tables["studentinf"].Rows[0]["contact"].ToString();  
     }
} 

推荐答案

查看我对 this [ ^ ]问题。 使用相同的技术来解决您的问题。



/ ravi
See my reply to this[^] question.  Use the same technique to solve your problem.

/ravi


这篇关于如何显示不同登录用户的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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