Click here to Skip to main content
15,885,730 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a registration form that you will have to enter the email address as the user name and password that you chose. I have the code for all of this I am stuck on one part. How do I get the user ID from one table to the other table when the user enters the email address and password into the form for that user to be submitted? To clear it up this is what I have:

For all the users I have a table that has all of their information in it. First Name, Last Name, Email Address, Address, Age, SS# and other things. Each user has an unique ID Number in that table. The other table is the password table. It holds the User ID, Email Address, Password and Level. How can I set the code to get the User ID, Email Address and level from one table to the password table? The user can only enter their email address and password.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using System.Security.Cryptography;

public partial class SubmitPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
            con.Open();
            string cmdStr = "Select count(*) from TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
            SqlCommand userExist = new SqlCommand(cmdStr, con);
            SqlCommand cmd = new SqlCommand("select INST_ID, EmailAddress from TableSecurity", con);
            int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
            if (temp == 1)
            {
                lblMessage.Text = "User Name Already Exist!!!";
            }
        }
    }

    protected void Submit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "Select INST_ID, EmailAddress from TableCEO where EmailAddress='" + TextBoxEA.Text + "'";
        string cmdStr2 = "Select INST_ID, EmailAddress from TableIALO where EmailAddress='" + TextBoxEA.Text + "'";
        string insCmd = "Insert into TableSecurity (EmailAddress, Password) values (@EmailAddress, @Password)";
        string insCmd2 = "Insert into TableSecurity (EmailAddress, Password) values (@EmailAddress, @Password)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        SqlCommand insertUser2 = new SqlCommand(insCmd2, con);
        insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        
        


        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();
            Response.Redirect("Login.aspx");
        }
        catch (Exception er)
        {
            Response.Write("An error occurred: " + er.Message);
        }
        finally
        {
        }
    }
    
}
Posted
Comments
Vinodh.B 18-Oct-13 1:15am    
Pls write down your table design and actual output and expected ouput .

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