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