ADO.NET provider for Kintone / Querying Data
Querying Data

The ADO.NET Provider for Kintone implements two classes you can use to perform CRUD (Create, Read, Update, and Delete) operations: DbDataReader and C1KintoneDataAdapter classes. The tabs below describe the interfaces and code implementations.

Querying With DbDataReader

The DbDataReader class can be used to fetch data in subset increments as required. It can retrieve data quicker than the C1KintoneDataAdapter as it retrieves data in pages. When you read data from the DbDataReader, it requests the succeeding page from the data source to load the result, which makes the data retrieval faster.

The following code examples demonstrate create, read, update, and delete operations from the data source using the DbDataReader.

 

Create Data

The example adds new records by executing the Insert command.

C#
Copy Code
static void InsertDataReader()
{
    string kintoneConnection = string.Format("Username={0};Password={1};Url={2}", Username, Password, Url);

    using (C1KintoneConnection conn = new C1KintoneConnection(kintoneConnection))
    {
        conn.Open();
        //Create Insert command
        C1KintoneCommand command = new C1KintoneCommand(conn, $"INSERT INTO Products(ProductName) VALUES('Lorem Ipsum')");
        //Execute Insert command
        int i = command.ExecuteNonQuery();
        if (i != -1)
        {
            Console.WriteLine("Insert operation successful !!! \n \n");
        }
    }
}

Read Data

This example retrieves data by executing the Select command.

C#
Copy Code
static void ReadDataReader()
{
    string kintoneConnection = string.Format("Username={0};Password={1};Url={2}", Username, Password, Url);

    using (C1KintoneConnection con = new C1KintoneConnection(kintoneConnection))
    {
        con.Open();
        //Create Read command
        var cmd = con.CreateCommand();
        cmd.CommandText = "SELECT  *  FROM Products";
        //Execute Read command and display fetched data
        DbDataReader rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Updated By"], rdr["ProductName"]));
        }
        Console.WriteLine("Read operation successful !!! \n \n");
    }
}

Update Data

This example modifies data by executing the Update command.

C#
Copy Code
static void UpdateDataReader()
{
    string kintoneConnection = string.Format("Username={0};Password={1};Url={2}", Username, Password, Url);

    using (C1KintoneConnection conn = new C1KintoneConnection(kintoneConnection))
    {
        conn.Open();
        //Create Update command
        C1KintoneCommand command = new C1KintoneCommand(conn, "UPDATE Products SET [ProductName]='Lorem Ipsum updated' WHERE ProductName = 'Lorem Ipsum'");

        //Execute Update command
        int i = command.ExecuteNonQuery();
        if (i != -1)
        {
            Console.WriteLine("Update operation successful !!! \n \n");
        }
    }
}

Delete Data

This example removes data by executing the Delete command.

C#
Copy Code
static void DeleteDataReader()
{
    string kintoneConnection = string.Format("Username={0};Password={1};Url={2}", Username, Password, Url);

    using (C1KintoneConnection conn = new C1KintoneConnection(kintoneConnection))
    {
        conn.Open();
        //Create Delete command
        C1KintoneCommand command = new C1KintoneCommand(conn, "DELETE FROM Products WHERE ProductName = 'Lorem Ipsum updated'");

        //Execute Delete command
        int i = command.ExecuteNonQuery();
        if (i != -1)
        {
            Console.WriteLine("Delete operation successful !!! \n \n");
        }
    }
}