DataConnector
ADO.NET provider for Kintone / Batch Processing
In This Topic
    Batch Processing
    In This Topic

    The ADO.NET Provider for Kintone allows the user to perform multiple operations with bulk data through C1KintoneDataAdapter. You can improve the process by executing many smaller batch requests. To control the size of each batch, you can set the C1KintoneDataAdapter's UpdateBatchSize property to a positive integer.

    Steps to perform batch processing:

    The provider translates all SQL queries in the batch into a single request. Below are the examples of different operations with bulk data.

    Bulk Insert

    The below code example creates a batch that inserts data in bulk and retrieves the new data.

    C#
    Copy Code
    using (C1KintoneConnection conn = new C1KintoneConnection(kintoneConnection))
    {
        //Populate Datatable
        C1KintoneDataAdapter adapter = new C1KintoneDataAdapter(conn, "Select * from Products");
        DataTable dataTable = new DataTable();
        adapter.Fill(dataTable);
    
        //Create Insert Query
        adapter.InsertCommand = new C1KintoneCommand(conn);
        adapter.InsertCommand.CommandText = "Insert into Products (Name, Quantity) values (@Name, @Quantity)";
        adapter.InsertCommand.Parameters.Add("@Name", "Name");//Query Parametres
        adapter.InsertCommand.Parameters.Add("@Quantity", "Quantity");          
        adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;
    
        //Perform insert operation
        DataRow productRow1 = dataTable.NewRow();
        productRow1["Name"] = "Product 3";
        productRow1["Quantity"] = 676;               
        dataTable.Rows.Add(productRow1);
        DataRow productRow2 = dataTable.NewRow();
        productRow2["Name"] = "Product 4";
        productRow2["Quantity"] = 506;              
        dataTable.Rows.Add(productRow2);
    
        //Set batch size to be updated
        adapter.UpdateBatchSize = 2;
        //Update database
        adapter.Update(dataTable);
        Console.WriteLine("Bulk insert successful !!! \n \n");
    

     

    Bulk Update

    A batch update additionally requires the primary key of each row to update. The below code example prepares a batch that updates data in bulk.

    C#
    Copy Code
    using (C1KintoneConnection conn = new C1KintoneConnection(kintoneConnection))
    {
        //Populate Datatable               
        C1KintoneDataAdapter adapter = new C1KintoneDataAdapter(conn, "Select * from Products");
        DataTable dataTable = new DataTable();
        adapter.Fill(dataTable);
        //Create Update Query
        adapter.UpdateCommand = new C1KintoneCommand(conn);
        adapter.UpdateCommand.CommandText = "UPDATE Products SET Quantity = @Quantity WHERE Name = @Name";//Update Query
        adapter.UpdateCommand.Parameters.Add("@Quantity", "Quantity");
        adapter.UpdateCommand.Parameters.Add("@Name", "Name");
        adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;
        //Perform Update operation
        DataRow bookRow1 = dataTable.Rows[0];
        bookRow1["Quantity"] = 100;
        DataRow bookRow2 = dataTable.Rows[4];
        bookRow2["Quantity"] = 200;
        //Set batch size to be updated
        adapter.UpdateBatchSize = 2;
        //Update database
        adapter.Update(dataTable);
        Console.WriteLine("Bulk update successful !!! \n \n");
    

     

    Bulk Delete

    The below code example creates a batch that deletes data in bulk. The primary key for each row is required.

    C#
    Copy Code
    using (C1KintoneConnection conn = new C1KintoneConnection(kintoneConnection))
    {
        //Populate Datatable  
        C1KintoneDataAdapter adapter = new C1KintoneDataAdapter(conn, "Select * from Products");
        DataTable dataTable = new DataTable();
        adapter.Fill(dataTable);
        //Create Delete command
        adapter.DeleteCommand = new C1KintoneCommand(conn);
        adapter.DeleteCommand.CommandText = "Delete from Products where Name = @Name";
        adapter.DeleteCommand.Parameters.Add("@Name", "Name");
        adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;
        //Perform delete operation
        DataRow productRow1 = dataTable.Rows[13];
        productRow1.Delete();
    
        DataRow productRow2 = dataTable.Rows[14];
        productRow2.Delete();
        //Set batch size to be updated
        adapter.UpdateBatchSize = 2;
        //Update database
        adapter.Update(dataTable);
        Console.WriteLine("Bulk delete successful !!! \n \n");