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

    You can update the Salesforce.com or Database.com data either by modifying data returned by the SalesforceDataAdapter class and then calling its Update method or by performing corresponding DML statements (INSERT, DELETE, UPDATE) via SalesforceCommand.

    Here is an example showing how to update Salesforce.com or Database.com data using SalesforceDataAdapter.

    using Devart.Data.Salesforce;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;";
            const string sql = "SELECT Id, LastName FROM Contact";
    
            using (SalesforceConnection connection = new SalesforceConnection(connectionString)) {
    
                connection.Open();
                DataTable table = new DataTable("Contact");
    
                using (SalesforceCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    using (SalesforceDataAdapter adapter = new SalesforceDataAdapter(command)) {
    
                        adapter.Fill(table);
    
                        adapter.UpdateCommand = new SalesforceCommand("UPDATE Contact SET LastName = @name WHERE Id = @id", connection);
    
                        adapter.UpdateCommand.Parameters.Add("id", SalesforceType.String).SourceColumn = "Id";
                        adapter.UpdateCommand.Parameters["id"].SourceVersion = DataRowVersion.Original;
                        adapter.UpdateCommand.Parameters.Add("name", SalesforceType.String).SourceColumn = "LastName";
    
                        DataRow firstrow = table.Rows[0];
                        firstrow["LastName"] = "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.Salesforce
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"
            Const sql As String = "SELECT Id, LastName FROM Contact"
    
            Using connection As New SalesforceConnection(connectionString)
    
                connection.Open()
                Dim table As New DataTable("Accounts")
    
                Using command As SalesforceCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Using adapter As New SalesforceDataAdapter(command)
                        adapter.Fill(table)
    
                        adapter.UpdateCommand = New SalesforceCommand("UPDATE Contact SET LastName = @name WHERE Id = @id", connection)
    
                        adapter.UpdateCommand.Parameters.Add("id", SalesforceType.String).SourceColumn = "Id"
                        adapter.UpdateCommand.Parameters("id").SourceVersion = DataRowVersion.Original
                        adapter.UpdateCommand.Parameters.Add("name", SalesforceType.String).SourceColumn = "LastName"
    
                        Dim firstrow As DataRow = table.Rows(0)
                        firstrow("LastName") = "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 Salesforce.com or Database.com data using SalesforceCommand.

    using Devart.Data.Salesforce;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;";
            const string sql = "UPDATE Contact SET Email = '[email protected]' WHERE LastName = 'sample name 1'";
    
            using (SalesforceConnection connection = new SalesforceConnection(connectionString)) {
    
                connection.Open();
                using (SalesforceCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    Console.WriteLine(command.ExecuteNonQuery());
                }
            }
            Console.ReadKey();
        }
    }
    
    
    Imports Devart.Data.Salesforce
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "Server=login.salesforce.com;User Id= [email protected];Password=mypassword;Security Token=qweASDzcx1234567890rtyui;"
            Const sql As String = "UPDATE Contact SET Email = '[email protected]' WHERE LastName = 'sample name 1'"
    
            Using connection As New SalesforceConnection(connectionString)
    
                connection.Open()
                Using command As SalesforceCommand = 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