Exemple #1
0
        /// <summary>
        /// Uses a select statement and the ADO.NET CommandBuilder
        /// to generate Insert,Update, and Delete statements, and load them onto an adapter
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="client"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        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);
        }
Exemple #2
0
        /// <summary>
        /// Uses a select statement and the ADO.NET CommandBuilder 
        /// to generate Insert,Update, and Delete statements, and load them onto an adapter
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="client"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        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;
        }