0

I am trying to create Google BigQuery Table Schema Explicitly, TableSchema.Fields.Add() method throws Object Reference Exception.

        TableSchema Schema = response.Schema;

        TableFieldSchema sc1 = new TableFieldSchema();
        sc1.Name = "CustomerID";
        sc1.Type = "STRING";
        sc1.Mode = "NULLABLE";

        Schema.Fields.Add(sc1); -- Throws Error.
demonplus
  • 5,613
  • 12
  • 49
  • 68
selva kumar
  • 1,086
  • 2
  • 11
  • 30
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Linda Lawton - DaImTo Jun 15 '15 at 13:27
  • I think you are supposed to build new Schema in order to mutate it, not to use one from response object. – Mosha Pasumansky Jun 15 '15 at 18:45
  • @Mosha Pasumansky, Exactly. I am trying to load CSV file into new table, so that i want to create TableSchema for that purpose, but not able to build new schema using above methods. Do you have any samples to build new schema using Google BigQuery. – selva kumar Jun 16 '15 at 05:11

1 Answers1

0

I can able to create new TableSchema in .NET client library by using below code.

TableSchema Schema = new TableSchema();
TableFieldSchema F1 = new TableFieldSchema();
F1.Name = "COLUMN NAME";
F1.Type = "STRING";
F1.Mode = "REQUIRED";

TableFieldSchema F2 = new TableFieldSchema();
F1.Name = "COLUMN NAME";
F1.Type = "INTEGER";
F1.Mode = "NULLABLE";

//Add N number of fields as per your needs

System.Collections.Generic.IList<TableFieldSchema> FS = new System.Collections.Generic.List<TableFieldSchema>();
FS.Add(F1);
FS.Add(F2);

Schema.Fields = FS;
selva kumar
  • 1,086
  • 2
  • 11
  • 30