dotConnect for Mailchimp Documentation
In This Topic
    Updating Data
    In This Topic

    You can update the Mailchimp data either by modifying data returned by the MailChimpDataAdapter class and then calling its Update method or by performing corresponding DML statements (INSERT, DELETE, UPDATE) via MailChimpCommand.

    Here is an example showing how to update Mailchimp data using MailChimpDataAdapter.

    using Devart.Data.MailChimp;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "api key=8b10fe893c9732d12befe0b7d846ffcb-us10;";
            const string sql = "SELECT Id, Name FROM Folders";
    
            using (MailChimpConnection connection = new MailChimpConnection(connectionString)) {
    
                connection.Open();
                DataTable table = new DataTable("Folders");
    
                using (MailChimpCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    using (MailChimpDataAdapter adapter = new MailChimpDataAdapter(command)) {
    
                        adapter.Fill(table);
    
                        adapter.UpdateCommand = new MailChimpCommand("UPDATE Folders SET Name = @name WHERE Id = @id", connection);
     
                        adapter.UpdateCommand.Parameters.Add("id", DbType.String).SourceColumn = "Id";
                        adapter.UpdateCommand.Parameters["id"].SourceVersion = DataRowVersion.Original;
                        adapter.UpdateCommand.Parameters.Add("name", DbType.String).SourceColumn = "Name";
    
                        DataRow firstrow = table.Rows[0];
                        firstrow["Name"] = "sample name 1";
                        Console.WriteLine(adapter.Update(table));
                    }
                }
                Console.WriteLine("Rows after update.");
    
                foreach (DataRow row in table.Rows) {
                    Console.WriteLine("{0}\t{1}", row[0], row[1]);
                }
            }
            Console.ReadKey();
        }
    
    }
    
    
    Imports Devart.Data.MailChimp
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "api key=8b10fe893c9732d12befe0b7d846ffcb-us10;"
            Const sql As String = "SELECT Id, Name FROM Folders"
    
            Using connection As New MailChimpConnection(connectionString)
    
                connection.Open()
                Dim table As New DataTable("Folders")
    
                Using command As MailChimpCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Using adapter As New MailChimpDataAdapter(command)
                        adapter.Fill(table)
    
                        adapter.UpdateCommand = New MailChimpCommand("UPDATE Folders SET Name = @name WHERE Id = @id", connection)
    
                        adapter.UpdateCommand.Parameters.Add("id", DbType.String).SourceColumn = "Id"
                        adapter.UpdateCommand.Parameters("id").SourceVersion = DataRowVersion.Original
                        adapter.UpdateCommand.Parameters.Add("name", DbType.String).SourceColumn = "Name"
    
                        Dim firstrow As DataRow = table.Rows(0)
                        firstrow("Name") = "sample name 1"
                        Console.WriteLine(adapter.Update(table))
    
                        Console.WriteLine("Rows after update.")
                        For Each row As DataRow In table.Rows
                            Console.WriteLine(row(0).ToString() & vbTab & row(1))
                        Next
                    End Using
                End Using
            End Using
            Console.ReadKey()
        End Sub
    
    End Module
    
    

    The following example updates Mailchimp data using MailChimpCommand.

    using Devart.Data.MailChimp;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "api key=8b10fe893c9732d12befe0b7d846ffcb-us10;";
            const string sql = "UPDATE Folders SET Name = 'sample name 2' WHERE Name = 'sample name 1'";
    
            using (MailChimpConnection connection = new MailChimpConnection(connectionString)) {
    
                connection.Open();
                using (MailChimpCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    Console.WriteLine(command.ExecuteNonQuery());
                }
            }
            Console.ReadKey();
        }
    }
    
    
    Imports Devart.Data.MailChimp
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "api key=8b10fd893c9732d72befe0b7d7e6f0cb-us10;"
            Const sql As String = "UPDATE Folders SET Name = 'sample name 2' WHERE Name = 'sample name 1'"
    
            Using connection As New MailChimpConnection(connectionString)
    
                connection.Open()
                Using command As MailChimpCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Console.WriteLine(command.ExecuteNonQuery())
                End Using
            End Using
            Console.ReadKey()
        End Sub
    
    End Module
    
    

    See Also

    Entity Framework  | Retrieving Data