簡體   English   中英

c#從postgresql中檢索_text類型

[英]c# retrieve _text type from postgresql

我有一個數組,如 [["64", "0", "0"], ["64", "7", "95"], ["61", "28", "165"], [" 60", "45", "200"]] 在我從 ruby​​ on rails 存儲的 Postgres 列中,我想在我的 C# 項目中檢索它。 當我這樣做時:

NpgsqlDataReader reader = command.ExecuteReader();
DataTable dt = new DataTable();
while (reader.Read())
{
    Console.WriteLine("{0}\t{1}", reader.GetName(0), reader.GetString(1));
}

我收到以下異常:

System.InvalidCastException: Can't cast database type _text to String 如何將此列值作為數組獲取但是當我這樣做時:

dt.Load(reader);

foreach (DataRow row in dt.Rows)
{                
    var points = row["points"];
    var json = new JavaScriptSerializer().Serialize(points);
    Console.WriteLine(json);
}

它返回 ["64","0","0","64","7","95","61","28","165","60","45","200" ] 這不是我想要的。

請嘗試:

string[,] result = row["points"] as string[,]; 

pgSql 定義了一個數組字段,所以它不能直接轉換為字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM