Excel Add-In for kintone

Build 21.0.7930

Updating Data

After Connecting from VBA, you are ready to update kintone from macros. The following sections show how to execute parameterized queries to update data. See Executing Parameterized Queries for a complete macro.

Insert

Call the Insert method to execute SQL INSERT statements.
public bool Insert(string queryString, object paramNames, object paramValues)

The Insert method returns a boolean indicating the success or failure of the statement execution and accepts the following parameters:

queryStringThe query to execute; for example, INSERT INTO Comments (Text) VALUES ('New to do')
paramNamesAn array with the named parameters used in the query. Required if using a parameterized query.
paramValuesAn array with the values that correspond to the parameter names. Required if using a parameterized query.

The following example inserts the values specified in the parameter arrays and displays a message box indicating the success or failure of the insert.

Dim nameArray
nameArray = Array("Text", "AppId")
Dim valueArray
valueArray = Array("Old to do", "1354841")
Dim module As New ExcelComModule
module.SetProviderName ("Kintone")
module.SetConnectionString ("User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid")
Query = "INSERT INTO Comments (Text, AppId) VALUES (@Text, @AppId)"
If module.Insert(Query, nameArray, valueArray) Then
  MsgBox "The insert was successful."
Else
  MsgBox "The insert failed."
End If
module.Close

Update

Call the Update method to execute SQL UPDATE statements.

public bool Update(string queryString, object paramNames, object paramValues)

The Update method returns a boolean indicating the success or failure of the statement execution and accepts the following parameters:

queryStringThe statement to execute.
paramNamesAn array with the named parameters used in the query. Required if using a parameterized query.
paramValuesAn array with the corresponding parameter values. Required if using a parameterized query.

The following example updates the values specified in the parameter arrays and displays a message box indicating the success or failure of the update.

Dim nameArray
nameArray = Array("Text", "AppId","Id")
Dim valueArray
valueArray = Array("Old to do", "1354841","123456")
Dim module As New ExcelComModule
module.SetProviderName ("Kintone")
module.SetConnectionString ("User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid")
Query = "UPDATE Comments SET Text=@Text, AppId=@AppId WHERE Id=@Id
If module.Update(Query, nameArray, valueArray) Then
  MsgBox "The update was successful."
Else
  MsgBox "The update failed."
End If
module.Close

Delete

Call the Delete method to execute SQL DELETE statements.
public bool Delete(string queryString, object paramNames, object paramValues)

The Delete method returns a boolean indicating the query's success or failure and accepts the following parameters:

queryStringThe query to execute; for example, SELECT CreatorName, Text FROM Comments WHERE AppId = '1354841'
paramNamesAn array with the named parameters used in the query. Required if using a parameterized query.
paramValuesAn array with the values that correspond to the parameter names. Required if using a parameterized query.

The following example deletes a record, specified by its key, and displays a message box indicating the success or failure of the delete.

Dim module As New ExcelComModule
module.SetProviderName ("Kintone")
module.SetConnectionString("User=myuseraccount;Password=mypassword;Url=http://subdomain.domain.com;GuestSpaceId=myspaceid")
Dim nameArray
nameArray = Array("Id")
Dim valueArray
valueArray = Array("123456")
Query = "DELETE FROM Comments WHERE Id='123456'"
If module.Delete(Query,nameArray,valueArray) Then
  MsgBox "The delete was successful."
Else
  MsgBox "The delete failed."
End If 
module.Close

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930