Click here to Skip to main content
15,890,670 members
Please Sign up or sign in to vote.
2.40/5 (2 votes)
See more:
I have a database with three tables. Table1, Table2 and Table3. When the code is running and the user puts in their username and password it is then saved into Table3. Table3 holds the username, password, UserID and Level. I am having trouble getting the UserID and Level to Table3 from Table1 and Table2. The way the code is now the user can setup a new user and that user information is saved into Table3 but without the UserID and Level. Is there a way I can correct this? What am I doing wrong?

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 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)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        SqlCommand insertUser2 = new SqlCommand(insCmd2, con);
        insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        insertUser.Parameters.AddWithValue("@accessLevel", TextBoxEA.Text);
        


        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();
            Response.Redirect("Login.aspx");
        }
        catch (Exception er)
        {
            lblMessage.Text = "User Already Exist";
        }
        finally
        {
        }
    }
   
}
Posted
Updated 28-Oct-13 7:41am
v3

1 solution

Have a look at your code...
SQL
insertUser.Parameters.AddWithValue("@EmailAddress", TextBoxEA.Text);
insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
insertUser.Parameters.AddWithValue("@accessLevel", TextBoxEA.Text);


You are trying to insert into accessLevel TextBoxEA.Text - the email address. If accessLevel has been defined as an integer you're not going to get anything saved by passing it a string. I suspect you didn't mean to do that and surprised that no exception was thrown by the DBMS
 
Share this answer
 
Comments
Mas11 4-Nov-13 6:48am    
Good Catch!

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