I have a array like [["64", "0", "0"], ["64", "7", "95"], ["61", "28", "165"], ["60", "45", "200"]] in Postgres column which I stored from ruby on rails, and I want to retrieve it in my C# project. When I do this:
NpgsqlDataReader reader = command.ExecuteReader();
DataTable dt = new DataTable();
while (reader.Read())
{
Console.WriteLine("{0}\t{1}", reader.GetName(0), reader.GetString(1));
}
I get the following exception:
System.InvalidCastException: Can't cast database type _text to String How can I get this column value as an Array But when I do:
dt.Load(reader);
foreach (DataRow row in dt.Rows)
{
var points = row["points"];
var json = new JavaScriptSerializer().Serialize(points);
Console.WriteLine(json);
}
it returns ["64","0","0","64","7","95","61","28","165","60","45","200"] which is not what I want.
Please try:
string[,] result = row["points"] as string[,];
pgSql has an array field defined, so it cannot convert to string directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.