Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I develop the signup page(signup.aspx) and also login page(login.aspx) in signup page user also upload their picture please modify the login code in the way that when user login only image upload by that user display on next page for ex(infor.aspx) i simply want logic in login.cs code
My database table name is Table1
SQL
ID int
Eamil varchar(20) primary key
password varchar(20)
confirmpassword varchar(20)
Name varchar(20)
country varchar(20)
Gender varchar(20)
year varchar(20)
month varchar(20)
date varchar(20)
Description varchar(20)
PictureFile image

login.cs
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite4\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
       con.Open();
       string query = "Select Password from Table1 Where Email='" + TextBox2.Text + "'";
       SqlCommand com = new SqlCommand(query, con);
       SqlDataReader rd;
       rd = com.ExecuteReader();
       while (rd.Read())
       {
           s = rd[0].ToString();
       }
       con.Close();
       if (s == TextBox1.Text)
       {
           Session["Email"] = TextBox2.Text;
           Response.Redirect("information.aspx");
       }
       else
       {
           //Response.Redirect("home.aspx");
           Response.Write("<script language='javascript'>alert( 'Invalid password or Email ' )</script>");

       }

Signup.cs
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite4\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
        con1.Open();
        SqlCommand sc = new SqlCommand("Select Email from Table1", con1);
        SqlDataReader rd;
        rd = sc.ExecuteReader();
        while (rd.Read())
        {
            // Label25.Text = rd["Stid"].ToString();
            if (rd["Email"].ToString().Equals(TextBoxEmail.Text))
            {
                Response.Write("<script language='javascript'>alert( 'Already Exsist ' )</script>");

                k = 1;

            }
        }
        con1.Close();
        if (k == 0)
        {
            string fileName = FileUpload1.PostedFile.FileName;
            int fileLength = FileUpload1.PostedFile.ContentLength;
            byte[] imageBytes = new byte[fileLength];
            FileUpload1.PostedFile.InputStream.Read(imageBytes, 0, fileLength);
            string connStr = ConfigurationManager.AppSettings["ConnStr"].ToString();
            using (SqlConnection conn = new SqlConnection(connStr))
            {

                string query1 = "insert into Table1(Email,Password,confirmPassword,Name,Country,Gender,Year,Date,Month,Description,PictureFile)values('" + TextBoxEmail.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBoxName.Text + "','" + TextBox1.Text + "','" + DropDownList1.Text + "','" + DropDownList4.Text + "','" + DropDownList2.Text + "','" + DropDownList3.Text + "','" + TextBox2.Text + "',@pictureFile)";
                SqlParameter[] prms = new SqlParameter[1];
                prms[0] = new SqlParameter("@pictureFile", SqlDbType.Image);
                prms[0].Value = imageBytes;
                using (SqlCommand cmd = new SqlCommand(query1, conn))
                {
                    cmd.Parameters.AddRange(prms);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }

                Response.Redirect("Login.aspx");

            }
Posted
Updated 18-Mar-11 8:58am
v2
Comments
Wendelius 18-Mar-11 14:59pm    
Edit: Pre tags added
Sandeep Mewara 18-Mar-11 15:30pm    
Why do I feel like reading the same thing yesterday too?

You have been told several times now: you have all the information you need.
When user login only image upload by that user display on next page[^]

Now, probably for the first time in your life, start thinking.

If you don't, then it is time for you to learn the Magic Words: "Do you want fries with that?"
You will need them, often, in your exciting new career in Retail Fast Food.
 
Share this answer
 
Another note: Instead of concatenating the values from UI elements directly into your SQL statement use parameters to avoid SQL injections etc: SqlParameter Class[^]

To give an example: Based on your code, it would be extremely easy to destroy your whole database by just adding proper statements to your email text box.
 
Share this answer
 
FYI: Don't code connection strings, DB query executing statements(cmd.ExecuteNonQuery()) and adding paramaters to sql Sp's in one page.

Try to put corresponding code blocks in appropriate Layes(Tiers)and that helps you to navigate through your code easily next time. Follow the standard coding rules. All the best!!

User can upload their beautiful images next to login page.
 
Share this answer
 
Comments
Raj Bose 18-Mar-11 15:51pm    
Good advice like it :)

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