Search Postgresql Archives

Bytea error in PostgreSQL 9.0

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux