dotConnect for Google BigQuery Documentation
Devart.Data.BigQuery Namespace / BigQueryDataReader Class
Members Example

On this page
    BigQueryDataReader Class
    On this page
    Reads a forward-only stream of rows from Google BigQuery.
    Syntax
    Remarks
    To create a BigQueryDataReader, you must call the ExecuteReader method of the BigQueryCommand object, rather than directly using a constructor.

    System.Data.Common.DbDataReader.IsClosed and RecordsAffected are the only properties that you can call after the BigQueryDataReader is closed. In some cases, you must call Devart.Common.DbDataReaderBase.Close before you can call RecordsAffected.

    Example
    The following example creates a BigQueryConnection, a BigQueryCommand, and a BigQueryDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the BigQueryDataReader, then the BigQueryConnection.
    public void ReadMyData(string myConnString)  {
            BigQueryConnection bigQueryConnection = new BigQueryConnection(myConnString);
            BigQueryCommand bigQueryCommand = (BigQueryCommand)bigQueryConnection.CreateCommand();
            bigQueryCommand.CommandText = "SELECT id, first_name, last_name FROM your_project.your_dataset.employees";
            bigQueryConnection.Open();
            BigQueryDataReader bigQueryReader = bigQueryCommand.ExecuteReader();
            try {
                    // Always call Read before accessing data.
                    while (bigQueryReader.Read()) {
                    Console.WriteLine(bigQueryReader.GetInt64(0) + " " + 
                    bigQueryReader.GetString(1) + " " + bigQueryReader.GetString(2));
            }
            }
            finally {
                    // always call Close when done reading.
                    bigQueryReader.Close();
    
                    // Close the connection when done with it.
                    bigQueryConnection.Close();
            }
    }
    Public Sub ReadMyData(ByVal myConnString As String)
            Dim bigQueryConnection As New BigQueryConnection(myConnString)
            Dim bigQueryCommand As BigQueryCommand = bigQueryConnection.CreateCommand()
                    bigQueryCommand.CommandText = "SELECT id, first_name, last_name FROM your_project.your_dataset.employees"
            bigQueryConnection.Open()
            Dim bigQueryReader As BigQueryDataReader = bigQueryCommand.ExecuteReader()
            Try
                    ' Always call Read before accessing data.
                    While bigQueryReader.Read()
                            Console.WriteLine(String.Concat(bigQueryReader.GetInt64(0), " ", _
                            bigQueryReader.GetString(1), " ", bigQueryReader.GetString(2)))
                    End While
            Finally
                    ' always call Close when done reading.
                    bigQueryReader.Close()
    
                            ' Close the connection when done with it.
                            bigQueryConnection.Close()
            End Try
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.Data.Common.DbDataReader
             Devart.Common.DbDataReaderBase
                Devart.Data.SqlShimDataReader
                   Devart.Data.BigQuery.BigQueryDataReader

    See Also