2 Replies - 299 Views - Last Post: 18 April 2013 - 05:54 AM Rate Topic: -----

#1 optix212  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 18
  • View blog
  • Posts: 453
  • Joined: 10-October 09

Adding rows to database

Posted 18 April 2013 - 12:02 AM

I am creating a simple login/register system that will add a row to a database filled with the users information when he/she registers. I have added a function called AddUser() to my form, and it seems to work just fine.. It isn't throwing any errors, or anything. The problem, though, is that it isn't adding any new data to my database. I don't know how to fix this, so I'm asking on here for maybe a turn in the right direction.. Here is the code for the AddUser() function:

        private void AddUser()
        {
            string username = registerUserName.Text;
            string password = registerPassword.Text;
            string confirmPass = registerConfirmPassword.Text;
            string email = registerEmail.Text;
            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(email);

            if (password != confirmPass)
            {
                MessageBox.Show("Passwords do not match");
            }
            else if (password.Length < 8)
            {
                MessageBox.Show("Password must be at least 8 characters long");
            }
            else if (!match.Success)
            {
                MessageBox.Show("Invalid Email");
            }
            else if (username == null)
            {
                MessageBox.Show("Must have Username");
            }
            else
            {
                DataRow newUserRow = loginsDataSet.Tables["Logins"].NewRow();

                newUserRow["Username"] = username;
                newUserRow["Password"] = password;
                newUserRow["Email"] = email;
                MessageBox.Show(loginsDataSet.Tables["Logins"].Rows.Count.ToString());
            }
        }



Is This A Good Question/Topic? 0
  • +

Replies To: Adding rows to database

#2 optix212  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 18
  • View blog
  • Posts: 453
  • Joined: 10-October 09

Re: Adding rows to database

Posted 18 April 2013 - 12:12 AM

I am an idiot.. I forgot to actually ADD the new row..

Here is the new code for programatically adding a new row:

                loginsDataSet.LoginsRow newUserRow = loginsDataSet.Logins.NewLoginsRow();

                newUserRow.Username = username;
                newUserRow.Password = password;
                newUserRow.Email = email;

                loginsDataSet.Logins.Rows.Add(newUserRow);
                MessageBox.Show("Thank you for Registering!");


Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: Adding rows to database

Posted 18 April 2013 - 05:54 AM

Good for you!

As an aside, I hope that you know that your email address validation is overly restrictive. It doesn't allow '+' in the local part.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1