To establish a connection to a CSV data source, the ADO.NET Provider can be used through the C1CSVConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:
The following code shows how a connection string can be configured by the C1CSVConnectionStringBuilder class and consumed by C1CSVConnection class to create a connection to CSV server. Through that connection, the data source can be queried, updated etc.
C# |
コードのコピー
|
---|---|
//JSON サービス URI。 const string csvUri = "sampleCSV.csv"; //接続文字列を設定します。 C1CSVConnectionStringBuilder connectionStringBuilder = new C1CSVConnectionStringBuilder(); connectionStringBuilder.Uri = csvUri; connectionStringBuilder.TrimValues = true; //接続を設定します。 C1CSVConnection con = new C1CSVConnection(connectionStringBuilder.ConnectionString); |
Alternatively, the connection string can be written directly as shown in the following code. The similar approach can be implemented in other DataConnectors for ADO.NET provider.
C# |
コードのコピー
|
---|---|
//接続文字列を作成します。 static string csvConnectionString = $"Uri='sampleCSV.csv'"; //接続を設定します。 C1CSVConnection con = new C1CSVConnection(csvConnectionString); |
The ADO.NET provider for CSV allows you to connect to local and https CSV resources. For connecting to these resources, you only need to set the Uri property to the CSV resource location. Additionally, you can set other properties such as TrimValues, ContainsHeaders which can be helpful in the manipulation of the CSV resource.
To connect to local file, you can create a connection string by setting the Uri property to CSV file as shown in the following code:
C# |
コードのコピー
|
---|---|
static string csvConnectionString = $"Uri='sampleCSV.csv'"; |
To connect to HTTP file, you can create a connection string by setting the Uri property to the HTTP or HTTPS URL of the CSV resource you want to access as a table, as shown in the following code:
C# |
コードのコピー
|
---|---|
static string documentConnectionString = $"Uri='https://docs.google.com/spreadsheets/d/e/2PACX-1vTgdxvUJhf8i6ri1a_y5gUUwKuFr3zz5J6h0W0gqWev7AT1BK916NJnD3YxB6KRouQXSf6cO5DoUqlm/pub?gid=1155993230&single=true&output=csv'"; |