Non vorrei dire una stupidaggine ma ho l'impressione che tu abbia utilizzato in modo improprio SqlCommandBuilder.
Questo è l'esempio su MSDN:
codice:
public static DataSet SelectSqlRows(string connectionString,
string queryString, string tableName)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(queryString, connection);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
connection.Open();
DataSet dataSet = new DataSet();
adapter.Fill(dataSet, tableName);
//code to modify data in DataSet here
builder.GetUpdateCommand();
//Without the SqlCommandBuilder this line would fail
adapter.Update(dataSet, tableName);
return dataSet;
}
}
Come vedi non è necessario impostare la proprietà InsertCommand del DataAdapter in quanto è il SqlCommandBuilder che la determina a partire dalla SelectCommand. Probabilmente associando il SqlCommandBuilder le successive modifiche di InsertCommand vengono ignorate. La soluzione, nel tuo caso, è quella di non utilizzare SqlCommandBuilder, ma impostare direttamente la InsertCommand del DataAdapter, come hai fatto nel secondo esempio.