0
votes

My question may be quite stupid but I'm an absolute beginner, and I have a top urgent project to do.

I have created a WinForm app which works with a database containing several tables. One of the tables is a users table which contains the following columns:

UserID - int, is identity = true| increment 1. UserName - nvarchar. Password - nvarchar.

VS2010 created a strongly typed Data set for me automatically, when I added the DB to my project.

I have created a form in which I have several text boxes. This form has a button that should update my dataset with information from several textboxes and than update the underlying database via the dataadapter.update() method.

Unfortunatly the data is never updated to the underlying database, I don't understand why and need your help. Thanks.

code sample (button click event):

LoginDataSetTableAdapters.LoginTableAdapter useraddadapter = new LoginDataSetTableAdapters.LoginTableAdapter();
LoginDataSet useraddset = new LoginDataSet();
LoginDataSet.LoginRow adduser = useraddset.Login.NewLoginRow();
adduser.UserName = textBoxUserName.Text;
adduser.Password = textBoxPassword.Text;
adduser.Email = textBoxEmail.Text;
adduser.Position = textBoxPosition.Text;
useraddset.Login.AddLoginRow(adduser);
useraddset.Tables[0].AcceptChanges();
useraddadapter.Update(useraddset.Login);
1

1 Answers

0
votes

Calling the AcceptChanges method will commit all changes in the DataSet or DataTable. If it is called before the Update method is called, no changes will be committed when the Update method is called, unless further changes have been made since AcceptChanges or AcceptChanges was called.