The ADO.NET provider for JSON provides a wide range of features that enable connectivity to JSON from .Net applications. The documentation will help you understand the C1.AdoNet.JSON namespace, which includes all the available classes that can be used to connect and retrieve data from JSON.
DataConnectors are mostly used in combination with other ComponentOne components, such as DataEngine and FlexPivot. The procedure below describes how to use the DataConnector in a console application within Visual Studio.
The ADO.NET provider for JSON can be used in any application. In this guide, a console application is created:
To use the ADO.NET provider for JSON in an application, the respective NuGet package should be added:
Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for JSON.
C# |
コードのコピー
|
---|---|
static string documentConnectionString = $"Data Model=Document;Uri='json_bookstore.json';Json Path='$.bookstore.books'"; |
C# |
コードのコピー
|
---|---|
static void ReadData() { Console.WriteLine("Query all Accounts..."); //データを取得します。 using(var con = new C1JsonConnection(documentConnectionString)) { con.Open(); var table = con.GetSchema("columns", new string[] { "books" }); ShowDataTable(table); var cmd = con.CreateCommand(); //コマンドを提供します。 cmd.CommandText = "Select * From books"; var reader = cmd.ExecuteReader(); } } //テーブルを表示します。 static void ShowDataTable(DataTable table, int length = 25) { foreach (DataColumn col in table.Columns) { Console.Write("{0,-" + length + "}", col.ColumnName); } Console.WriteLine(); foreach (DataRow row in table.Rows) { foreach (DataColumn col in table.Columns) { if (col.DataType.Equals(typeof(DateTime))) Console.Write("{0,-" + length + ":d}", row[col]); else if (col.DataType.Equals(typeof(decimal))) Console.Write("{0,-" + length + ":C}", row[col]); else Console.Write("{0,-" + length + "}", row[col]); } Console.WriteLine(); } } |