ADO.NET provider for Google Analytics > データのクエリ |
The ADO.NET Provider for Google Analytics implements two classes you can use to perform the Read operation: DbDataReader and C1GoogleAnalyticsDataAdapter classes. The tabs below describe the classes and code implementations.
The DbDataReader class can be used to fetch data in subset increments as required. It can retrieve data quicker than the C1GoogleAnalyticsDataAdapter as it retrieves data in pages. When you read data from the DbDataReader, it requests the succeeding page from the data source to load the result, which makes the data retrieval faster.
The following code examples demonstrate read operation from the data source using the DbDataReader and retrieves data by executing the Select command.
C# |
コードのコピー
|
---|---|
static void ReadDataReader() { //接続文字列を定義します。 string connectionString = string.Format("Key File={0};View Id={1}", KeyFile, ViewId); //コマンドを定義します。 string sql = "SELECT Source, Sessions FROM Traffic WHERE Sessions > 500 AND StartDate = '14DaysAgo' AND EndDate = 'Today'"; //データを取得します。 using DataReader using (var con = new C1GoogleAnalyticsConnection(connectionString)) { con.Open(); var command = con.CreateCommand(); command.CommandText = sql; var reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(String.Format("{0} --> \t\t{1}", reader["Source"], reader["Sessions"])); } } } |
The following code demonstrate read operation from the data source using the C1GoogleAnalyticsDataAdapter and retrieves data by executing the Select command.
C# |
コードのコピー
|
---|---|
static void ReadDataAdapter() { //接続文字列を定義します。 string connectionString = string.Format("Key File={0};View Id={1}", KeyFile, ViewId); //コマンドを定義します。 string sql = "SELECT Source, Sessions FROM Traffic WHERE Sessions > 500 AND StartDate = '14DaysAgo' AND EndDate = 'Today'"; //データを取得します。 using (var con = new C1GoogleAnalyticsConnection(connectionString)) { con.Open(); //Using C1GoogleAnalyticsDataAdapter C1GoogleAnalyticsDataAdapter gaAdapter = new C1GoogleAnalyticsDataAdapter(con, sql); DataTable dt = new DataTable(); gaAdapter.Fill(dt); //取得したデータを表示します。 foreach (DataRow row in dt.Rows) { Console.WriteLine("{0} --> \t\t{1}", row["Source"], row["Sessions"]); } } } |