Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a form that a user can signup with a username and password. I have a database that has two tables. Table1 has the user profile already in it. UserID, Name, Age, Address, City, State, Email, Level. In Table2 it is setup to have UserID, Email, Password, Level. I have a code that when the user puts in their email and password in the textboxes and click submit it is saved into Table2 but it is missing the UserId and Level. Is there a way I can get these two fields to Table2 without entering it into a textboxes? I am stuck on this part!

C#
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, accessLevel, EmailAddress from TableCEO insert into TableSecurity where EmailAddress='" + TextBoxEA.Text + "'";
        string cmdStr2 = "Select INST_ID, accessLevel, EmailAddress from TableIALO insert into TableSecurity 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);
        

        
    }
   
}


Ok This is what I have tried so far but it still does not work. I have updated the code with what I have changed. The only thing that is saved into Table2 is the Email and the password. How can I get the UserID and Level into Table2 along with the email and password?
Posted
Updated 29-Oct-13 3:03am
v2
Comments
Harshil_Raval 29-Oct-13 6:08am    
Yes you can do it easily..
first select your desired fields from table1 by email id(email id should be unique in table1).
select UserID,Level from table1 where emailid=txtemail.Text
That's it. you have now userid and level. now you can insert it in table2.
Computer Wiz99 29-Oct-13 7:50am    
Ok. Sorry for the long delay. Where would I replace that into my code? I thought I did it here:
string cmdStr = "Select INST_ID, accessLevel, EmailAddress from TableCEO where EmailAddress='" + TextBoxEA.Text + "'";
string cmdStr2 = "Select INST_ID, accessLevel, EmailAddress from TableIALO where EmailAddress='" + TextBoxEA.Text + "'";
string insCmd = "Insert into TableSecurity (EmailAddress, Password, accessLevel) values (@EmailAddress, @Password, @accessLevel)";
string insCmd2 = "Insert into TableSecurity (EmailAddress, Password, accessLevel) values (@EmailAddress, @Password, @accessLevel)";

1 solution

As Harshi answer is Exact but may be i can add some more info on this!!

first select fields from table1 by email id,.
select UserID,Level from table1 where emailid=txtemail.Text

Then
 
Share this answer
 
Comments
Computer Wiz99 29-Oct-13 8:25am    
Naresh1277, Thanks for the info add to the answer. I thought I was doing that in my code? Where do I need to make the changes? Can you show me the code that you came up with?

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