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

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

    Here is an example showing how to update BigCommerce data using BigcommerceDataAdapter.

    using Devart.Data.Bigcommerce;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            var monitor = new Devart.Data.Bigcommerce.BigcommerceMonitor() { IsActive = true };
    
            const string connectionString = "server=https://my-store.mybigcommerce.com/api/v2/; userid=testuser;Authentication Token=be307be4cb782457be9136608a3b2a459009dc43;";
            const string sql = "SELECT id, Name FROM Products";
    
            using (BigcommerceConnection connection = new BigcommerceConnection(connectionString)) {
    
                connection.Open();
                DataTable table = new DataTable("Products");
    
                using (BigcommerceCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    using (BigcommerceDataAdapter adapter = new BigcommerceDataAdapter(command)) {
    
                        adapter.Fill(table);
    
                        adapter.UpdateCommand = new BigcommerceCommand("UPDATE Products 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.Bigcommerce
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "server=https://my-store.mybigcommerce.com/api/v2/; userid=testuser;Authentication Token=be307be4cb782457be9136608a3b2a459009dc43;"
            Const sql As String = "SELECT id, Name FROM Products"
    
            Using connection As New BigcommerceConnection(connectionString)
    
                connection.Open()
                Dim table As New DataTable("Products")
    
                Using command As BigcommerceCommand = connection.CreateCommand()
    
                    command.CommandText = sql
                    Using adapter As New BigcommerceDataAdapter(command)
                        adapter.Fill(table)
    
                        adapter.UpdateCommand = New BigcommerceCommand("UPDATE Products 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 BigCommerce data using BigcommerceCommand.

    using Devart.Data.Bigcommerce;
    ...
    class Program
    {
    
        static void Main(string[] args) {
    
            const string connectionString = "server=https://my-store.mybigcommerce.com/api/v2/; userid=testuser;Authentication Token=be307be4cb782457be9136608a3b2a459009dc43;";
            const string sql = "UPDATE Products SET Price = 100 WHERE Name = 'sample name 1'";
    
            using (BigcommerceConnection connection = new BigcommerceConnection(connectionString)) {
    
                connection.Open();
                using (BigcommerceCommand command = connection.CreateCommand()) {
    
                    command.CommandText = sql;
                    Console.WriteLine(command.ExecuteNonQuery());
                }
            }
            Console.ReadKey();
        }
    }
    
    
    Imports Devart.Data.Bigcommerce
    ...
    Module Module1
    
        Sub Main()
    
            Const connectionString As String = "server=https://my-store.mybigcommerce.com/api/v2/; userid=testuser;Authentication Token=be307be4cb782457be9136608a3b2a459009dc43;"
            Const sql As String = "UPDATE Products SET Price = 100 WHERE Name = 'sample name 1'"
    
            Using connection As New BigcommerceConnection(connectionString)
    
                connection.Open()
                Using command As BigcommerceCommand = 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