Cmdlets for SharePoint

Build 20.0.7654

SELECT INTO ステートメント

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

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

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

C#

String connectionString = "User=MyUserAccount;Password=MyPassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;";

using (SharePointConnection connection = new SharePointConnection(connectionString)) {
  SharePointCommand cmd = new SharePointCommand("SELECT Id, Location INTO [csv://Calendar.txt] FROM [Calendar] WHERE Location = 'Chapel Hill' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=MyUserAccount;Password=MyPassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;" 

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

C#

String connectionString = "User=MyUserAccount;Password=MyPassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;";

using (SharePointConnection connection = new SharePointConnection(connectionString)) {
  SharePointCommand cmd = new SharePointCommand("SELECT * INTO [Calendar] IN [csv://filename=c:/Calendar.csv;delimiter=tab] FROM [Calendar] WHERE Location <> 'Chapel Hill'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

Dim connectionString As [String] = "User=MyUserAccount;Password=MyPassword;Auth Scheme=NTLM;URL=http://sharepointserver/mysite;" 

Using connection As New SharePointConnection(connectionString)
  Dim cmd As New SharePointCommand("SELECT * INTO [Calendar] IN [csv://filename=c:/Calendar.csv;delimiter=tab] FROM [Calendar] WHERE Location <> 'Chapel Hill'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

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