0

Hi I have a webform to allow users to register this information is stored in a Clients tables but I would like some of the information to be stored in another table that will store the username, security question and answer. I tried using two separate insert commands but it didn't work. I then saw on the internet that you joining the two inserts can work like this:

                        cmd.CommandText = "INSERT INTO Clients(ClientName, Address, Town, County, PhoneNumber, MobileNumber, Username, [Password], EmailAddress) VALUES(@clientName, @address, @town, @county, @phone, @mobile, @username, @password, @email) INSERT INTO ClientResetPass(Username, SecretQuestion, SecretAnswer) VALUES (@user, @secretQ, @secretA)";
                        cmd.CommandType = CommandType.Text;
                        cmd.Parameters.AddWithValue("@clientName", txtClientName.Text);
                        cmd.Parameters.AddWithValue("@address", txtAdd.Text);
                        cmd.Parameters.AddWithValue("@town", txtTown.Text);
                        cmd.Parameters.AddWithValue("@county", txtCounty.Text);
                        cmd.Parameters.AddWithValue("@phone", txtPhone.Text);
                        cmd.Parameters.AddWithValue("@mobile", txtMob.Text);
                        cmd.Parameters.AddWithValue("@username", txtNewUser.Text);
                        cmd.Parameters.AddWithValue("@password", txtNewPassword.Text);
                        cmd.Parameters.AddWithValue("@email", txtNewEmail.Text);
                        cmd.Parameters.AddWithValue("@user", txtNewUser.Text);
                        cmd.Parameters.AddWithValue("@secretQ", txtSecretQ.Text);
                        cmd.Parameters.AddWithValue("@secretA", txtSecretA.Text);
                        conn.Open();
                        cmd.ExecuteNonQuery();

But this is also not working, anyone any ideas how I can insert into two tables at the same time.

Thanks in advance

2
Contributors
2
Replies
10
Views
3 Years
Discussion Span
Last Post by laura301019
0
    cmd.CommandText = "INSERT INTO Clients(ClientName, Address, Town, County, PhoneNumber, MobileNumber, Username, [Password], EmailAddress) VALUES(@clientName, @address, @town, @county, @phone, @mobile, @username, @password, @email)" 
    cmd.CommandType = CommandType.Text;
    cmd.Parameters.AddWithValue("@clientName", txtClientName.Text);
    cmd.Parameters.AddWithValue("@address", txtAdd.Text);
    cmd.Parameters.AddWithValue("@town", txtTown.Text);
    cmd.Parameters.AddWithValue("@county", txtCounty.Text);
    cmd.Parameters.AddWithValue("@phone", txtPhone.Text);
    cmd.Parameters.AddWithValue("@mobile", txtMob.Text);
    cmd.Parameters.AddWithValue("@username", txtNewUser.Text);
    cmd.Parameters.AddWithValue("@password", txtNewPassword.Text);
    cmd.Parameters.AddWithValue("@email", txtNewEmail.Text);
                            conn.Open();
                            cmd.ExecuteNonQuery();
                            conn.Close();
    cmd.CommandText = "INSERT INTO ClientResetPass(Username, SecretQuestion, SecretAnswer) VALUES (@user, @secretQ, @secretA)";
                            cmd.Parameters.AddWithValue("@user", txtNewUser.Text);
                            cmd.Parameters.AddWithValue("@secretQ", txtSecretQ.Text);
                            cmd.Parameters.AddWithValue("@secretA", txtSecretA.Text);
                            conn.Open();
                            cmd.ExecuteNonQuery();
                            conn.Close();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.