问题
I am using C# with postgresql. In the database I have a table named test
and in this table I have a column named arr
that it's datatype is double[]
and I stored multiple record like this {1, 1, 2, 3, 0, 5, 1, 4}
. Now, how to return those records into C# program and stored in a list for example List<double[]> arr1 = new List<double[]>();
Who can help me?
回答1:
For array datatypes, all you have to do is cast the result as an array of double:
NpgsqlConnection conn = new NpgsqlConnection(connectionString);
conn.Open();
NpgsqlCommand cmd = new NpgsqlCommand("select arr from test", conn);
NpgsqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
double[] myArray = (double[])reader.GetValue(0);
// do your bidding
}
reader.Close();
回答2:
Here is a walkthrough, Using PostgreSQL in your C# (.NET): Using PostgreSQL in your C# (.NET)
You will need to give us some specific problems that you are having so we can help solve the problem.
来源:https://stackoverflow.com/questions/39329681/how-to-read-array-field-from-database-using-c