Adf.Base.Data.SqlProvider.SetUpAdapter C# (CSharp) Method

SetUpAdapter() public method

Provides information to setup the data adapter by the connection of System.Data.IDbConnection.
public SetUpAdapter ( DataSources datasource, IDbConnection connection, IAdfQuery query ) : IDbDataAdapter
datasource Adf.Core.Data.DataSources
connection IDbConnection The represents an open connection to a data source.
query IAdfQuery The whose SQL information is to be retrieved.
return IDbDataAdapter
        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;
        }