public void FRegister() { connection.Open(); string InsertIntoNewAddress = "INSERT INTO addresses(Street,Number,City,Post_code) VALUES('" + Street.Trim() + "','" + HouseNumber.Trim() + "','" + City.Trim() + "','" + PostCode.Trim() + "' )"; MySqlCommand InsertIntoNewAddressCmd = new MySqlCommand(InsertIntoNewAddress, connection); InsertIntoNewAddressCmd.ExecuteNonQuery(); string selectAddressId = "SELECT ID FROM addresses WHERE Street='" + Street.Trim() + "' AND Number ='" + HouseNumber.Trim() + "' AND City='" + City.Trim() + "' AND Post_code='" + PostCode.Trim() + "'"; MySqlCommand SelectAddressIdCmd = new MySqlCommand(selectAddressId, connection); var addressid = (Int32)SelectAddressIdCmd.ExecuteScalar(); string InsertIntoNewUser = "******" + Name.Trim() + "','" + Surname.Trim() + "',@addressId,'" + Login.Trim() + "','" + Password.Trim() + "','" + Email.Trim() + "','" + PhoneNumber.Trim() + "',1,0)"; MySqlCommand InsertIntoNewUserCmd = new MySqlCommand(InsertIntoNewUser, connection); InsertIntoNewUserCmd.Parameters.AddWithValue("@addressId", addressid); InsertIntoNewUserCmd.ExecuteNonQuery(); connection.Close(); }