この記事ではCData ADO.NET Provider for WooCommerce を使ってPowerBuilder からWooCommerce にアクセスする方法を説明します。
CData ADO.NET providers は、PowerBuilder を含むMicrosoft .NET をサポートするあらゆるプラットフォームまたは開発テクノロジーから使用できる、使いやすい標準準拠のデータプロバイダーです。 この記事では、CData ADO.NET Provider for WooCommerce をPowerBuilder で使う方法について説明します。
CData ADO.NET Provider for WooCommerce を使ってデータを取得し読み書きを実行する基本的なPowerBuilder アプリケーションを作成する方法について説明します。
- 新規WPF Window Application ソリューションで、接続プロパティに必要なすべてのビジュアルコントロールを追加します。一般的な接続文字列は次のとおりです:
Url=https://example.com/; ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad; ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5; InitiateOAuth=GETANDREFRESH
WooCommerce supports the following authentication methods: one-legged OAuth1.0 Authentication and standard OAuth2.0 Authentication.
Connecting using one-legged OAuth 1.0 Authentication
Specify the following properties (NOTE: the below credentials are generated from WooCommerce settings page and should not be confused with the credentials generated by using WordPress OAuth2.0 plugin):
- ConsumerKey
- ConsumerSecret
Connecting using WordPress OAuth 2.0 Authentication
- .NET コントロールからDataGrid コントロールを追加します。
-
DataGrid コントロールのカラムを設定します。Account テーブルからいくつかのカラムを以下に示します:
<DataGrid AutoGenerateColumns="False" Margin="13,249,12,14" Name="datagrid1" TabIndex="70" ItemsSource="{Binding}"> <DataGrid.Columns> <DataGridTextColumn x:Name="idColumn" Binding="{Binding Path=Id}" Header="Id" Width="SizeToHeader" /> <DataGridTextColumn x:Name="nameColumn" Binding="{Binding Path=ParentId}" Header="ParentId" Width="SizeToHeader" /> ... </DataGrid.Columns> </DataGrid>
- CData ADO.NET Provider for WooCommerce アセンブリへの参照を追加します。
DataGrid 接続
ビジュアルエレメントが設定されたら、Connection、Command、およびDataAdapter のような標準のADO.NET オブジェクトを使ってSQL クエリの結果をDataTable に表示することができます:
System.Data.CData.WooCommerce.WooCommerceConnection conn
conn = create System.Data.CData.WooCommerce.WooCommerceConnection(connectionString)
System.Data.CData.WooCommerce.WooCommerceCommand comm
comm = create System.Data.CData.WooCommerce.WooCommerceCommand(command, conn)
System.Data.DataTable table
table = create System.Data.DataTable
System.Data.CData.WooCommerce.WooCommerceDataAdapter dataAdapter
dataAdapter = create System.Data.CData.WooCommerce.WooCommerceDataAdapter(comm)
dataAdapter.Fill(table)
datagrid1.ItemsSource=table.DefaultView
上のコードは、指定したクエリからDataGrid にデータをバインドできます。