Azavea.NijPredictivePolicing.Common.DB.DataClient.GetMagicAdapter C# (CSharp) Method

GetMagicAdapter() public static method

Uses a select statement and the ADO.NET CommandBuilder to generate Insert,Update, and Delete statements, and load them onto an adapter
public static GetMagicAdapter ( DbConnection conn, IDataClient client, string sql ) : DbDataAdapter
conn System.Data.Common.DbConnection
client IDataClient
sql string
return System.Data.Common.DbDataAdapter
        public static DbDataAdapter GetMagicAdapter(DbConnection conn, IDataClient client, string sql)
        {
            var cmd = client.GetCommand(sql, conn);
            var dba = client.GetDataAdapter(cmd);
            var builder = client.GetCommandBuilder(dba);

            dba.InsertCommand = builder.GetInsertCommand(true);
            dba.DeleteCommand = builder.GetDeleteCommand(true);
            dba.UpdateCommand = builder.GetUpdateCommand(true);

            if (dba.InsertCommand != null)
                dba.InsertCommand.CommandTimeout = client.QueryTimeout;

            if (dba.DeleteCommand != null)
                dba.DeleteCommand.CommandTimeout = client.QueryTimeout;

            if (dba.UpdateCommand != null)
                dba.UpdateCommand.CommandTimeout = client.QueryTimeout;

            return dba;
        }