【问题标题】:Get column names of sql query when using bigquery API in c#在c#中使用bigquery API时获取sql查询的列名
【发布时间】:2020-11-25 15:25:25
【问题描述】:

如何打印所有列名? Console.WriteLine(row.RawRow.ETag); 不起作用,它会打印空行

这是我目前的代码

static void Main(string[] args)
    {
        List<string> rows = new List<string>();
        string projectId = "project-id 123";
        var client = BigQueryClient.Create(projectId);
        string sql = @"SELECT * FROM table";
        var res = client.ExecuteQuery(sql, parameters: null);

        foreach (var row in res)
            Console.WriteLine(row["id"])
            //rows.Add(row["id"])
    }

【问题讨论】:

  • 你能在 foreach 循环中检查调试器吗?
  • 我找到了解决方案,谢谢

标签: c# google-bigquery


【解决方案1】:

其中一个例子有你的答案

Here

public List<T> Execute<T>(string sql)
{
    var client = BigQueryClient.Create(projectId);

    List<T> result = new List<T>();
    try
    {
        string query = sql;
        BigQueryResults results = client.ExecuteQuery(query, parameters: null);
        List<string> fields = new List<string>();

        foreach (var col in results.Schema.Fields)
        {
            fields.Add(col.Name);
        }

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2020-10-24
    • 2016-07-21
    相关资源
    最近更新 更多