0
votes

I am unable to import user entered data from .cs to tables. I got 2 tables one taking all user details while other takes the username(First name) and Password. Except the password and username the data gets into the details table. Here is the code from .cs

public partial class signUp : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {

    }

    protected void btnReg_Click(object sender, EventArgs e)
    {
        string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;


        using (SqlConnection con = new SqlConnection(cs))
        {

            //string encryption = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1");
            SqlCommand cmd2 = new SqlCommand("sp_PasswordStorage", con);
            SqlCommand cmd = new SqlCommand("sp_procedure", con);
            cmd2.CommandType = CommandType.StoredProcedure;
            cmd.CommandType = CommandType.StoredProcedure;

            if (Page.IsValid)
            {
                cmd.Parameters.AddWithValue("@Fname", txtFname.Text);
                cmd2.Parameters.AddWithValue("@uname", txtFname.Text);
                cmd2.Parameters.AddWithValue("@pswd", Encryption(txtPassword.Text));
                cmd.Parameters.AddWithValue("@Lname", txtLname.Text);
                cmd.Parameters.AddWithValue("@Age", txtAge.Text);
                cmd.Parameters.AddWithValue("@eid", txtEmail.Text);
                cmd.Parameters.AddWithValue("@pno", txtPhone.Text);
                cmd.Parameters.AddWithValue("@city", txtCity.Text);
                cmd.Parameters.AddWithValue("@country", txtCountry.Text);
                cmd.Parameters.AddWithValue("@gender", dropGender.SelectedItem.Value);
                cmd.Parameters.AddWithValue("@role", dropRole.SelectedItem.Value);

                con.Open();
                cmd.ExecuteNonQuery();
                //MessageBox.Show("Registration successfully");
                Server.Transfer("MainPage.aspx", true);
            }
            else
            {
                MessageBox.Show("Registration Failed");
                MessageBox.Show("Please Try Again Later");
                Server.Transfer("MainPage.aspx", true);
            }
        }
    }
    public string Encryption(string value)
    {
        SHA1 algorithm = SHA1.Create();
        byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value));
        string sh1 = "";
        for (int i = 0; i < data.Length; i++)
        {
            sh1 += data[i].ToString("x2").ToUpperInvariant();
        }
        return sh1;
    }

}

}

Any help would be appreciated, thank you :)

1
What do you expect to happen? What actually happens? Do any exceptions occur at runtime? (and if so, what are they)? - mjwills
Might be worth wrapping the code in a catch? - JonE
What is wrong with current code? Do you get any error? Did you debug and check what is happening in the code? Did you check the db if data is inserted or not? You are executing only cmd not cmd2. Did you notice that? - Chetan
No there is no error, it just functions as normal. And in the database 1 table gets the record while the other don't. And I dont know about Wrapconcept will look into that. - Rahul Anand

1 Answers

2
votes

I think, it just to execute both command.

cmd.ExecuteNonQuery();
cmd2.ExecuteNonQuery();