dotConnect for Mailchimp Documentation
In This Topic
    Bulk Data Loading
    In This Topic

    MailChimpLoader component is used for bulk uploading a large number of records to Mailchimp.

    To start uploading data, create a MailChimpLoader component. Then you may tweak its BatchSize property. BatchSize property determines a maximal number of records in a batch. After this you need to specify columns to load data. You may do it either manually, using the Columns property, or you may use the CreateColumns method to retrieve table columns information from the table specified in the TableName property. Then call the Open method and use the SetValue method to set values for the row fields. To switch to the next row, call the NextRow method.

    After you have finished loading data, call the Close method. This mthod sends the last batch to the server.

    The following example demonstrates using the MailChimpLoader class.

        using (var connection = new MailChimpConnection("api key=8b10fe893c9732d12befe0b7d846ffcb-us10;API Version=V3;")) {
            connection.Open();
    
            MailChimpLoader loader = new MailChimpLoader("Folders", connection);
            loader.Columns.Add("Name", DbType.String, 0, 0, 0);
            loader.Columns.Add("Type", DbType.String, 0, 0, 0);
    
            try {
                loader.Open();
                for (int i = 1; i <= 10; i++) {
                    loader.SetValue("Name", "Test " + i);
                    loader.SetValue("Type", "Campaign");
                    loader.NextRow();
                }
                loader.Close();
            }
            catch (MailChimpException ex) {
    
                // process exception
            }
        }
    
    
    
    
        Using connection As New MailChimpConnection("api key=8b10fe893c9732d12befe0b7d846ffcb-us10;API Version=V3;")
            connection.Open()
    
            Dim loader As New MailChimpLoader("Folders", connection)
            loader.Columns.Add("Name", DbType.String, 0, 0, 0)
            loader.Columns.Add("Type", DbType.String, 0, 0, 0)
    
            Try
                loader.Open()
                For i As Integer = 1 To 10
                    loader.SetValue("Name", "Test " & i)
                    loader.SetValue("Type", "Campaign")
                    loader.NextRow()
                Next
                loader.Close()
    
            Catch ex As MailChimpException
                'process exception
    
            End Try
        End Using
    
    
    

    After calling the Close method you can retrieve the results of data loading operation as an array of structs with the GetResults method.

    Note that dotConnect for MailChimp includes two different loader classes: Devart.Data.MailChimp.MailChimpLoader and Devart.Data.MailChimpV2.MailChimpLoader. These classes have the same interface and implement similar functionality, but they use different MailChimp API versions. Devart.Data.MailChimp.MailChimpLoader is intended for use with a connection using MailChimp API v3, and Devart.Data.MailChimpV2.MailChimpLoader is for a connection using MailChimp API v3.

    Devart.Data.MailChimp.MailChimpLoader provides much better efficiency than Devart.Data.MailChimpV2.MailChimpLoader because of MailChimp API v2 limitations. Devart.Data.MailChimpV2.MailChimpLoader should be used only in case when you need to load very large volume of data via MailChimp API v2.