Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
C#
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
Updated 11-Dec-12 11:16am
v2

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;
 
Share this answer
 
v2
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;
 
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