ADO.NET Provider for JSON

Build 20.0.7593

SELECT INTO ステートメント

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

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

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

C#

String connectionString = "DataModel=Relational;URI=C:\people.json";

using (JSONConnection connection = new JSONConnection(connectionString)) {
  JSONCommand cmd = new JSONCommand("SELECT personal.name.first, personal.name.last INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "DataModel=Relational;URI=C:\people.json" 

Using connection As New JSONConnection(connectionString)
  Dim cmd As New JSONCommand("SELECT personal.name.first, personal.name.last INTO [csv://NorthwindOData.txt] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

String connectionString = "DataModel=Relational;URI=C:\people.json";

using (JSONConnection connection = new JSONConnection(connectionString)) {
  JSONCommand cmd = new JSONCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "DataModel=Relational;URI=C:\people.json" 

Using connection As New JSONConnection(connectionString)
  Dim cmd As New JSONCommand("SELECT * INTO [NorthwindOData] IN [csv://filename=c:/NorthwindOData.csv;delimiter=tab] FROM [NorthwindOData] WHERE personal.name.last = 'ana.trujilo@northwind.org'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7593