Bytea error in PostgreSQL 9.0 - Mailing list pgsql-general

From tuanhoanganh
Subject Bytea error in PostgreSQL 9.0
Date
Msg-id AANLkTi=r1ZDoDfefdyisiX_pExmxyqmy6NvT+EMrS8Hq@mail.gmail.com
Whole thread Raw
Responses Re: Bytea error in PostgreSQL 9.0  ("Mark Felder" <feld@feld.me>)
List pgsql-general
I have program work with bytea, this field store image. Program work well in postgresql 8.3.9 but error in postgresql 9.0
Here is code to write image to database

FileStream srcStream = new FileStream(file_name, FileMode.Open, FileAccess.Read);
byte[] arrImage = new byte[srcStream.Length];
int read = srcStream.Read(arrImage, 0, arrImage.Length);

string sql = "INSERT INTO hrnvpict(ma_nv,pict) VALUES(@ma_nhan_vien ,@arrImage)";
Npgsql.NpgsqlConnection c = Public.cn;
Npgsql.NpgsqlCommand comm = new NpgsqlCommand(sql, c);
comm.Parameters.Add(new NpgsqlParameter("@arrImage", DbType.Binary)).Value = arrImage;
comm.Parameters.Add(new NpgsqlParameter("@ma_nhan_
vien", DbType.String, 40)).Value = _ma_nv;
comm.ExecuteNonQuery();

And Here is code to read image from database

string cmd = "select pict from hrnvpict where trim(ma_nv)= '" + _ma_nv + "'";
Npgsql.NpgsqlConnection c = Public.cn;
Npgsql.NpgsqlCommand comm = new NpgsqlCommand(cmd, c);
Byte[] result = (Byte[])comm.ExecuteScalar();
MemoryStream pic = new MemoryStream(result);
pictureBox1.Image = Image.FromStream(pic);  //<- 9.0 error here "parameter is not valid"

My postgresql 8.3 install is made by msi download from www.postgresql.org. Postgresql 9 install is made by EnterpriseDB, it has LC_COLLATE = 'English_United States.1252' and LC_CTYPE = 'English_United States.1252' (In 8.3 I cannot found this)

How to fix this. Please help me. Sorry for my English.

Tuan Hoang Anh

pgsql-general by date:

Previous
From: tuanhoanganh
Date:
Subject: Bytea error in PostgreSQL 9.0
Next
From: "Mark Felder"
Date:
Subject: Re: Bytea error in PostgreSQL 9.0