public virtual IDbDataAdapter SetUpAdapter(DataSources datasource, IDbConnection connection, IAdfQuery query)
{
var da = (SqlDataAdapter) GetAdapter();
if (query != null)
{
da.TableMappings.Add("Table", query.LeadTable());
var selectCommand = (SqlCommand) GetCommand(datasource, connection, query);
da.SelectCommand = selectCommand;
// create command builder for a new command, so we can customize the insert command
var newda = new SqlDataAdapter(selectCommand);
// Create and associate a commandbuilder which can generate insert and update queries for the DataAdapter. This is a necessary step!
var commandBuilder = new SqlCommandBuilder(newda);
da.InsertCommand = commandBuilder.GetInsertCommand();
da.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
da.UpdateCommand = commandBuilder.GetUpdateCommand();
da.DeleteCommand = commandBuilder.GetDeleteCommand();
}
return da;
}