Stefan Orr
Stefan Orr

Reputation: 311

Converting postgres box to .Net NpgsqlBox

I am trying to connect to a postgres database and pull out a box data type and parse it into a NpgsqlBox.

I was hoping there would be a constructor such as:

    new NpgsqlBox(reader.GetString(0));

But cannot find anything. I could split the string manually and use another constructor:

    new NpgsqlBox(getUpperRight(reader.GetString(0)), getLowerLeft(reader.GetString(0)));

Although I'm hoping for a nicer solution.

Any help would be appreciated.

Thanks

Upvotes: 1

Views: 127

Answers (1)

Hambone
Hambone

Reputation: 16397

I'm pretty sure for any nonstandard datatype you can simply use GetValue and then cast it as the proper datatype:

NpgsqlCommand cmd = new NpgsqlCommand("select * from my_box", conn);
NpgsqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
    NpgsqlBox b = (NpgsqlBox)reader.GetValue(0);
}

reader.Close();

Upvotes: 1

Related Questions