Ivan

Ivan

  • NA
  • 22
  • 0

data not being saved? newbie here :)

Jan 1 2010 7:20 PM
I am quite confused as to why my data is not being saved.

I have a form that allows the user to fill out their information.  When the user clicks on the Save button, the program does everything except save the data into the database.

Anyone know why this would happen and what I should be looking for?

Below is what the action for my "Save" button
[code] private void btnSave_Click(object sender, EventArgs e)
        {
            DialogResult result;

            result = MessageBox.Show("Are you sure you want to save your changes?", "Save Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                _user.insertUser();

                MessageBox.Show("New User Saved!");

                 //Not hiding correctly after data is saved.
                frmNewUser close = new frmNewUser();
                close.Hide();
            }[/code]

Below is code that my "Save" button calls.
[code]        public void insertUser()
        {
            cmdInsert.Parameters["@FirstName"].Value = _firstName;
            cmdInsert.Parameters["@LastName"].Value = _lastName;

            con.Open();

            int rowsAffected;
            rowsAffected = cmdInsert.ExecuteNonQuery();

            con.Close();
        }[/code]

I am just trying it out with only Firstname and lastname for now.

I have declared what I need to:
[code]        private int _userID = 0;
        private string _firstName = "";
        private string _lastName = "";
[/code]

and

[code]public int UserID
        {
            get { return _userID; }
            set { _userID = value; }
        }

        public string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        public string LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }
[/code]

Yes, I have believe I have set up everything for my cmdInsert:
[code]INSERT INTO Users
                         (FirstName, LastName)
VALUES        ([@FirstName], [@LastName])[/code]

and I have the Parameters set up for @FirstName and @LastName respectively.

almost forgot, I also have this inserted in my form too:
[code]private Users _user = new Users();[/code]

Can anyone see what I am doing wrong here?  The program connects to the database, it just doesnt save anything.  It adds a new line, but doesnt save any information.

Thanks,
Ivan


Answers (9)