From: | tuanhoanganh <hatuan05(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Bytea error in PostgreSQL 9.0 |
Date: | 2010-12-14 05:06:32 |
Message-ID: | AANLkTi=r1ZDoDfefdyisiX_pExmxyqmy6NvT+EMrS8Hq@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
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Felder | 2010-12-14 06:27:44 | Re: Bytea error in PostgreSQL 9.0 |
Previous Message | tuanhoanganh | 2010-12-14 05:03:38 | Bytea error in PostgreSQL 9.0 |