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

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

    Here is an example showing how to update QuickBooks data using QuickBooksDataAdapter.

    using Devart.Data.QuickBooks;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "Company Id=1234567890;Access " +
                "Token=asdqerTYUJcom5DSKL0djSSBEEFcJohjCGXixTTOM4Z8UpiX;Access Token " +
                "Secret=ojVArHdmHagedPRIIVtP8DCQNUbGkloK7Rgct59x;Consumer " +
                "Key=vbnrdKcCHaccybn1fbwje3UJLOJm1e;Consumer Secret=649QYsbe76LfeFbhajG6ccaeG8pobxbkiL1De0DS;";
            const string sql = "SELECT Id, DisplayName FROM Customer";
    
            using (QuickBooksConnection connection = new QuickBooksConnection(connectionString)) {
    
                connection.Open();
                DataTable table = new DataTable("Customer");
    
                using (QuickBooksCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    using (QuickBooksDataAdapter adapter = new QuickBooksDataAdapter(command)) {
    
                        adapter.Fill(table);
    
                        adapter.UpdateCommand = new QuickBooksCommand("UPDATE Customer SET DisplayName = @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 = "DisplayName";
    
                        DataRow firstrow = table.Rows[0];
                        firstrow["DisplayName"] = "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.QuickBooks
    ...
    Module Module1
    
            Const connectionString As String = "Company Id=1234567890;Access " & _
                "Token=asdqerTYUJcom5DSKL0djSSBEEFcJohjCGXixTTOM4Z8UpiX;Access Token " & _
                "Secret=ojVArHdmHagedPRIIVtP8DCQNUbGkloK7Rgct59x;Consumer " & _
                "Key=vbnrdKcCHaccybn1fbwje3UJLOJm1e;Consumer Secret=649QYsbe76LfeFbhajG6ccaeG8pobxbkiL1De0DS;"
    
            Using connection As New QuickBooksConnection(connectionString)
    
                connection.Open()
                Dim table As New DataTable("Customer")
    
                Using command As QuickBooksCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Using adapter As New QuickBooksDataAdapter(command)
                        adapter.Fill(table)
    
                        adapter.UpdateCommand = New QuickBooksCommand("UPDATE Customer SET DisplayName = @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 = "DisplayName"
    
                        Dim firstrow As DataRow = table.Rows(0)
                        firstrow("DisplayName") = "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 QuickBooks data using QuickBooksCommand.

    using Devart.Data.QuickBooks;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "Company Id=1234567890;Access " +
                "Token=asdqerTYUJcom5DSKL0djSSBEEFcJohjCGXixTTOM4Z8UpiX;Access Token " +
                "Secret=ojVArHdmHagedPRIIVtP8DCQNUbGkloK7Rgct59x;Consumer " +
                "Key=vbnrdKcCHaccybn1fbwje3UJLOJm1e;Consumer Secret=649QYsbe76LfeFbhajG6ccaeG8pobxbkiL1De0DS;";
            const string sql = "UPDATE Customer SET Title = 'sample title 1' WHERE DisplayName = 'sample name 1'";
    
            using (QuickBooksConnection connection = new QuickBooksConnection(connectionString)) {
    
                connection.Open();
                using (QuickBooksCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    Console.WriteLine(command.ExecuteNonQuery());
                }
            }
            Console.ReadKey();
        }
    }
    
    
    Imports Devart.Data.QuickBooks
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "Company Id=1234567890;Access " & _
                "Token=asdqerTYUJcom5DSKL0djSSBEEFcJohjCGXixTTOM4Z8UpiX;Access Token " & _
                "Secret=ojVArHdmHagedPRIIVtP8DCQNUbGkloK7Rgct59x;Consumer " & _
                "Key=vbnrdKcCHaccybn1fbwje3UJLOJm1e;Consumer Secret=649QYsbe76LfeFbhajG6ccaeG8pobxbkiL1De0DS;"
            Const sql As String = "UPDATE Customer SET Title = 'sample title 1' WHERE DisplayName = 'sample name 1'"
    
            Using connection As New QuickBooksConnection(connectionString)
    
                connection.Open()
                Using command As QuickBooksCommand = 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