title: Edited dataset do not update the database and return a concurrency violation error (C#)
body: <p>I am synchronizing data from different tables (about 20 tables) from Sybase database which I access through ODBC and a SQL Server (my main database for this project).</p>
  
  <p>When I launch the function to sync the data (only one way for the moment from Sybase to SQLServer), nothing happen and i get a concurrency violation error: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."</p>
  
  <p>The table on the SQL server has 96 columns and the one on Sybase only 94.  I had two columns in the SQL Server table for synchronization purpose. The SQL server table is empty before the synchronization the first time but the sybase database has already 21 rows.</p>
  
  <p>You may have a look to the code below to understand it better:</p>
  
  <pre><code>            try
              {
              //Connect to the erp Sybase database through ODBC
              OdbcConnection myConnection;
              //OdbcCommand myCommand;
              string MySQLRequest = "SELECT * FROM toto";
              string tableName = "toto";
  
              myConnection = new OdbcConnection("dsn=blabla;UID=bla;PWD=bla;");  
              //settings of the current database
              myConnection.Open();
  
  
              //get the data from MangoERP and store it into a dataset
              OdbcDataAdapter dasyb = new OdbcDataAdapter(MySQLRequest, myConnection);
              DataSet dserp = new DataSet(); //94columns
              dasyb.Fill(dserp, tableName);
              int dserpcount=dserp.Tables[0].Rows.Count;
  
              //get the data from MangoPMS and store it into a dataset
              SqlDataAdapter dasql = new SqlDataAdapter(MySQLRequest, mango_pms.Properties.Settings.Default.ConnectionStringSQLServer);
              DataSet dspms = new DataSet();//96columns
              dasql.Fill(dspms, tableName);
              int dspmscount = dspms.Tables[0].Rows.Count;
  
              //merge the dataset together
              if (dserpcount &gt; 0)
              {
                  dspms.Tables[0].Merge(dserp.Tables[0], false, MissingSchemaAction.Ignore); 
                  dspmscount = dspms.Tables[0].Rows.Count;
              }
              string dtutcnow=DateTime.UtcNow.ToString();
  
              for (int i = 0; i &lt; dspmscount; i++)
              {
                  if (dspms.Tables[0].Rows[i]["erpsyncdate"].ToString() == "")
                  {
                      dspms.Tables[0].Rows[i]["erpsyncdate"] = dtutcnow;
                  }
                  if (dspms.Tables[0].Rows[i]["erpsync"].ToString() == "")
                  {
                      dspms.Tables[0].Rows[i]["erpsync"] = 2; //1=pms, 2=erp  
                  }
              }
  
              //create an SqlCommandBuilder
              SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dasql); 
  
              //save back to pms table
              dasql.Update(dspms, tableName);
  
              //Close the connections
              dasyb.Dispose();
              dasql.Dispose();
              myConnection.Close();
  
          }
          catch
          {
              MessageBox.Show("Can not synchronize from ERP database!");
          }
  </code></pre>
  
  <p>Do you have any idea why I can not save the data from the dataset dspms. I checked with the Data vizualiser there is 21 rows inside (same as in the sybase databse) after merging.</p>
  
  <p>Cheers,
  LB</p>