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

Reply via email to