ADO.NET Provider for Lohaco

Build 21.0.7930

SELECT INTO ステートメント

SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。

SQL クエリを使ったデータのエクスポート

次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。

C#

String connectionString = "SellerId = sellerid;SSl Client Cert = path of the cert file;SSL Client Cert Type = PEMKEY_FILE;";

using (LohacoConnection connection = new LohacoConnection(connectionString)) {
  LohacoCommand cmd = new LohacoCommand("SELECT ItemCd, ItemName INTO [csv://Items.txt] FROM [Items] WHERE ItemName = 'Bob' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "SellerId = sellerid;SSl Client Cert = path of the cert file;SSL Client Cert Type = PEMKEY_FILE;" 

Using connection As New LohacoConnection(connectionString)
  Dim cmd As New LohacoCommand("SELECT ItemCd, ItemName INTO [csv://Items.txt] FROM [Items] WHERE ItemName = 'Bob'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

String connectionString = "SellerId = sellerid;SSl Client Cert = path of the cert file;SSL Client Cert Type = PEMKEY_FILE;";

using (LohacoConnection connection = new LohacoConnection(connectionString)) {
  LohacoCommand cmd = new LohacoCommand("SELECT * INTO [Items] IN [csv://filename=c:/Items.csv;delimiter=tab] FROM [Items] WHERE ItemName = 'Bob'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "SellerId = sellerid;SSl Client Cert = path of the cert file;SSL Client Cert Type = PEMKEY_FILE;" 

Using connection As New LohacoConnection(connectionString)
  Dim cmd As New LohacoCommand("SELECT * INTO [Items] IN [csv://filename=c:/Items.csv;delimiter=tab] FROM [Items] WHERE ItemName = 'Bob'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

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