title: Can't save the dataset changes to the database in C# - Visual Studio 2013
body: <p>[SOLVED]
  SOLUTION: When you execute the program inside visual studio it won't commit the changes to the database, but instead, it will work with a copy. When you deploy your program to an executable file, this executable is able to modify permanently your database. Hope this helps anyone :)</p>
  
  <p>As i've said in this question <a href="https://stackoverflow.com/questions/28051351/bindingsource-and-tableadapter-changes-not-commiting-to-the-database-c-visua">HERE</a>, I can't save the changes of my dataset to my DataBase. I tried to follow this tutorial <a href="https://yadavsachin.wordpress.com/2012/07/31/save-dataset-changes-to-database-in-c/comment-page-1/#comment-68" rel="nofollow noreferrer">HERE</a> and couldn't get it to work either: The program compiles and executes, but the new data isn't committed to the DB. Here's the code I wrote following the turorial.</p>
  
  <p>//METHOD INSIDE MY SIGN UP WINDOWS FORM</p>
  
  <pre><code>    public static SqlDataAdapter GetuserRecord()
      {
          SqlConnection connection = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\DatabaseJogo.mdf;Integrated Security=True");
          string query = "Select * from dbo.[user]";
  
          SqlCommand command = new SqlCommand(query, connection);
          connection.Open();
          SqlDataAdapter adp = new SqlDataAdapter(command);
          MessageBox.Show("CONNECTION SUCCESFUL");
          return adp;
      }
  </code></pre>
  
  <p>//WHEN MY SIGN UP BUTTON IS CLICKED:</p>
  
  <pre><code>            SqlDataAdapter adp = GetuserRecord();
              DataSet ds = new DataSet();
  
              adp.Fill(ds);
  
              DataRow newRow = ds.Tables[0].NewRow();
              newRow["login"] = loginText.Text.Trim();
              newRow["name"] = nameText.Text.Trim();
              newRow["age"] = int.Parse(ageText.Text.Trim());
              newRow["graphicsScore"] = trackBar1.Value;
              newRow["storyScore"] = trackBar2.Value;
              newRow["gameplayScore"] = trackBar3.Value;
              newRow["password"] = passwordText.Text.Trim();
              newRow["isAdmin"] = isAdmin.Checked;
              newRow["sex"] = sex.Text.Trim();
  
              ds.Tables[0].Rows.Add(newRow);
  
              SqlCommandBuilder commandBuilder = new SqlCommandBuilder(adp);
  
              adp.UpdateCommand = commandBuilder.GetUpdateCommand(true);
              adp.InsertCommand = commandBuilder.GetInsertCommand(true);
              adp.DeleteCommand = commandBuilder.GetDeleteCommand(true);
  
              adp.Update(ds);
  </code></pre>
  
  <p>EDIT: CHANGED THE CODE TO A NEW ONE, BUT THE PROBLEM IS STILL THE SAME. IF YOU WANT TO TAKE A LOOK, HERE IT IS:</p>
  
  <pre><code>                //TRY 3 SQL
              //https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.commit(v=vs.110).aspx
              SqlConnection connection = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|\\DatabaseJogo.mdf;Integrated Security=True");
              connection.Open();
  
              SqlCommand command = connection.CreateCommand();
              SqlTransaction transaction;
  
              transaction = connection.BeginTransaction("SIGNUP");
  
              command.Connection = connection;
              command.Transaction = transaction;
              try
              {
                  command.CommandText = "INSERT INTO [user] ([login], [name], [age], [graphicsScore], [storyScore], [gameplayScore], [password], [isAdmin], [sex]) VALUES (@login, @name, @age, @graphicsScore, @storyScore, @gameplayScore, @password, @isAdmin, @sex);";
                  command.Parameters.Add("@login", SqlDbType.NChar, 50).Value = loginText.Text.Trim();
                  command.Parameters.Add("@name", SqlDbType.NChar, 50).Value = nameText.Text.Trim();
                  command.Parameters.Add("@age", SqlDbType.Int).Value = int.Parse(ageText.Text.Trim());
                  command.Parameters.Add("@graphicsScore", SqlDbType.Int).Value = trackBar1.Value;
                  command.Parameters.Add("@storyScore", SqlDbType.Int).Value = trackBar2.Value;
                  command.Parameters.Add("@gameplayScore", SqlDbType.Int).Value = trackBar3.Value;
                  command.Parameters.Add("@password", SqlDbType.NChar, 50).Value = passwordText.Text.Trim();
                  command.Parameters.Add("@isAdmin", SqlDbType.Bit).Value = isAdmin.Checked;
                  command.Parameters.Add("@sex", SqlDbType.NChar).Value = sex.Text.Trim();
                  command.ExecuteNonQuery();
  
                  transaction.Commit();
                  MessageBox.Show("COMMITTED");
              }
              catch (Exception expt)
              {
                  MessageBox.Show(expt.Message);
                  try
                  {
                      transaction.Rollback();
                  }
                  catch (Exception ex2)
                  {
                      // This catch block will handle any errors that may have occurred 
                      // on the server that would cause the rollback to fail, such as 
                      // a closed connection.
                      MessageBox.Show("Rollback Exception Type: " + ex2.GetType());
                      MessageBox.Show("  Message: " + ex2.Message);
                  }
              }
              //connection.UpdateDatabase(ds);
  
              connection.Close();
  </code></pre>