Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
first i create database fields as follows Login Id,Firstnmae,Lastnmae and password
 
values as follows 1,ram,sam,123 etc table name entry.
 
First Design page as follows;
 
Username txt_username(textbox)
Password txt_password (textbox)
 
Insert (button) CLear(button)
 
when i type username and password values from the entry table such as login id 1 and password from the entry table and click the insert button it shows the message valid loginid and password.when i type wrong username and password it shows the message invalid loginid and password.
 

Second Design page as follows
 
Firstname txt_firstname(textbox)
Lastname txt_lastname(textbox)
 
when i click the insert buton from the first desing page it goes to second design page and output as
 
in that page i want the output as
Firstname ram
Lastname sam
 
From the entry table(database).
 
for the oupput how to write the code and in which page code has to be write please mention.it will be great useful for me.
 
First design page code as follows;
protected void Button1_Click1(object sender, EventArgs e)
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("select LoginID,Password from entry where LoginID = '" + txt_username.Text + "' and Password = '" + txt_password.Text + "'", con);
       
      SqlDataReader  dr = cmd.ExecuteReader();
 
        if (dr.HasRows)
        {
            Session["LoginID"] = txt_username.Text;
            dr.Close();
            con.Close();
            Label3.Text = "Valid loginid and password";
            Label3.ForeColor = System.Drawing.Color.DarkRed;
            Server.Transfer("default2.aspx");
        }
        else
        {
            Label3.Text = "Invalid loginid and password";
            Label3.ForeColor = System.Drawing.Color.DarkGreen;
        }
 
    }
Please help me.
Posted 11-Dec-12 4:18am
Edited 11-Dec-12 11:16am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

BUTTON1 CLICK:
 

protected void Button1_Click1(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("select * from entry where LoginID = '" + txt_username.Text + "' and Password = '" + txt_password.Text + "'", con);
 
SqlDataReader dr = cmd.ExecuteReader();
 
if (dr.HasRows)
{
Session["LoginID"] = txt_username.Text;
string fname=dr.GetValue(1).ToString();//get the first name...
string lname=dr.GetValue(2).ToString();//get the last name...
Session["firstname"]=fname;//use session variable to send the first name
Session["lastname"]=lname;//use session variable to send the last name
dr.Close();
con.Close();
Label3.Text = "Valid loginid and password";
Label3.ForeColor = System.Drawing.Color.DarkRed;
Server.Transfer("default2.aspx");
}
else
{
Label3.Text = "Invalid loginid and password";
Label3.ForeColor = System.Drawing.Color.DarkGreen;
}
 
}
 
 

at Second Page_Load() design 2Textbox
 
string a=Session["firstname"].ToString();//get the session variable & assign to a 
string b=Session["lastname"].ToString();//get the session variable & assign to b 
textbox1.text=a;
textbox2.text=b;
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use session like
 

 protected void LoginButton_Click(object sender, EventArgs e)
    {
 
        ValidateUser(txtUserName.Text.Trim(), txtPassword.Text.Trim());
Session["fname"]=txtUserName;//use session variable to send the first name
Session["lastname"]=txtlastName;//use session variable to send the last name
    }
 
    private void ValidateUser(string user, string pwd)
    { SqlConnection conn =new SqlConnection();
 
    conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ROKER_S (Dgvbv)\OnlineTestWEB\OnlineTestWEB\App_Data\TestEXAM.mdf;Integrated Security=True;User Instance=True");
        string sqlcmd="select * from LoginTable where UserName=@UserName and Password=@Password";
        SqlCommand cmd = new SqlCommand(sqlcmd, conn);
        cmd.Parameters.AddWithValue("@UserName", user);
        cmd.Parameters.AddWithValue("@Password", pwd);
        conn.Open();
 
        SqlDataAdapter DA = new SqlDataAdapter(cmd);
        DataSet DS = new DataSet();
        cmd.ExecuteScalar();
        DA.Fill(DS);
 
        if (DS.Tables[0].Rows.Count > 0)
        {
            Response.Redirect("Default.aspx");
 
        }
        else
        {
            Response.Write("Invalid UserID Or Password");
        
        }
        conn.Close();
    }
}
 

now at 2nd page use like...
 

at Second Page_Load() design 2Textbox
 
string a=Session["firstname"].ToString();//get the session variable & assign to a 
string b=Session["lastname"].ToString();//get the session variable & assign to b 
label1.text=a;
label2.text=b;
  Permalink  

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

  Print Answers RSS
0 Schatak 394
1 OriginalGriff 365
2 _Amy 115
3 Sergey Alexandrovich Kryukov 109
4 Andreas Gieriet 100
0 OriginalGriff 7,097
1 Sergey Alexandrovich Kryukov 5,623
2 Maciej Los 3,504
3 Peter Leow 3,373
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100