Bytea error in PostgreSQL 9.0

From: tuanhoanganh <hatuan05(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org, npgsql-general(at)gborg(dot)postgresql(dot)org
Subject: Bytea error in PostgreSQL 9.0
Date: 2010-12-14 05:03:38
Message-ID: AANLkTinYh=_2sBUmdB33jLtROgn_u470xPHPh_LgNQqi@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message tuanhoanganh 2010-12-14 05:06:32 Bytea error in PostgreSQL 9.0
Previous Message John R Pierce 2010-12-14 03:25:37 Re: Defining a Connection String in Windows XP