D
Dennis Wagner
Hi everyone!
I was playing a little with VC++ 2005 Express for evaluation purposes
(and out of curiosity) when I stumbled over some problems. I have a set
of binary data in a postgresql-table. I managed to insert the data via
the npgsql-data-provider. I can also read string and numeric values, but
when it comes to reading the data out of the db and writing it to disk I
fail.
I tried the following (I did this on another computer and type from mind
here so don't bother typos plz):
String^ statement = "SELECT data FROM jpegimages WHERE \"ID\" = " +
Convert::ToString(newObject->GetID()) + ";";
NpgsqlCommand^ command = gcnew NpgsqlCommand(statement, this->conn);
NpgsqlDataReader^ reader = command->ExecuteReader();
// I know there is only one row...
reader->Read();
if (reader[0] != IntPrt::Zero) {
array<Byte>^ bytes = (array<Byte>^)(reader[0]);
bufferedWriter->Write(bytes);
...
The code compiles without errors but when it is run I get "Cast not
valid" Exceptions at the "array<Bytes.."-line.
There isn't much info in the help about stuff like this. The docs for
the postgres-data-provider are written against c# (which I didn't intent
to use in this special case) where one can use a simple "byte[]"-construct.
Any help is highly appreicated.
regards...
....Dennis
I was playing a little with VC++ 2005 Express for evaluation purposes
(and out of curiosity) when I stumbled over some problems. I have a set
of binary data in a postgresql-table. I managed to insert the data via
the npgsql-data-provider. I can also read string and numeric values, but
when it comes to reading the data out of the db and writing it to disk I
fail.
I tried the following (I did this on another computer and type from mind
here so don't bother typos plz):
String^ statement = "SELECT data FROM jpegimages WHERE \"ID\" = " +
Convert::ToString(newObject->GetID()) + ";";
NpgsqlCommand^ command = gcnew NpgsqlCommand(statement, this->conn);
NpgsqlDataReader^ reader = command->ExecuteReader();
// I know there is only one row...
reader->Read();
if (reader[0] != IntPrt::Zero) {
array<Byte>^ bytes = (array<Byte>^)(reader[0]);
bufferedWriter->Write(bytes);
...
The code compiles without errors but when it is run I get "Cast not
valid" Exceptions at the "array<Bytes.."-line.
There isn't much info in the help about stuff like this. The docs for
the postgres-data-provider are written against c# (which I didn't intent
to use in this special case) where one can use a simple "byte[]"-construct.
Any help is highly appreicated.
regards...
....Dennis