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

    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();

Thank you so much, this works perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.