怎么能用bit类型呢,那就是最多一个字节来描述。image,应该使用oid。 看下边的例子: using System; using Npgsql; using NpgsqlTypes; using System.Drawing; using System.IO;//metod whos take picture oid from databasepublic int takeOID(int id){ //it's a metod whos connect to database and return picture oid
BazySQL pir = new BazySQL(Login.DaneUzera[8]);
string pytanko = String.Format("select rysunek from k_rysunki where idtowaru = " + idtowaru.ToString());
return liczba;}//take a picture from database and convert to Image typepublic Image pobierzRysunek(int idtowaru){ NpgsqlConnection Polacz = new NpgsqlConnection();
Polacz.ConnectionString = Login.DaneUzera[8].ToString(); //its metod whos return connection string
Polacz.Open();
NpgsqlTransaction t = Polacz.BeginTransaction();
LargeObjectManager lbm = new LargeObjectManager(Polacz);
LargeObject lo = lbm.Open(takeOID(idtowaru),LargeObjectManager.READWRITE); //take picture oid from metod takeOID
byte[] buf = new byte[lo.Size()];
buf = lo.Read(lo.Size());
MemoryStream ms = new MemoryStream();
ms.Write(buf,0,lo.Size());
lo.Close();
t.Commit();
Polacz.Close();
Polacz.Dispose();
Image zdjecie = Image.FromStream(ms);
return zdjecie;}//next I just use this metodpictureBox1.Image = Image pobierzRysunek(1);
看下边的例子:
using System;
using Npgsql;
using NpgsqlTypes;
using System.Drawing;
using System.IO;//metod whos take picture oid from databasepublic int takeOID(int id){ //it's a metod whos connect to database and return picture oid
BazySQL pir = new BazySQL(Login.DaneUzera[8]);
string pytanko = String.Format("select rysunek from k_rysunki where idtowaru = " + idtowaru.ToString());
string[] wartosci = pir.OddajSelectArray(pytanko);
int liczba = int.Parse(wartosci[0].ToString());
return liczba;}//take a picture from database and convert to Image typepublic Image pobierzRysunek(int idtowaru){ NpgsqlConnection Polacz = new NpgsqlConnection();
Polacz.ConnectionString = Login.DaneUzera[8].ToString(); //its metod whos return connection string
Polacz.Open();
NpgsqlTransaction t = Polacz.BeginTransaction();
LargeObjectManager lbm = new LargeObjectManager(Polacz);
LargeObject lo = lbm.Open(takeOID(idtowaru),LargeObjectManager.READWRITE); //take picture oid from metod takeOID
byte[] buf = new byte[lo.Size()];
buf = lo.Read(lo.Size());
MemoryStream ms = new MemoryStream();
ms.Write(buf,0,lo.Size());
lo.Close();
t.Commit();
Polacz.Close();
Polacz.Dispose();
Image zdjecie = Image.FromStream(ms);
return zdjecie;}//next I just use this metodpictureBox1.Image = Image pobierzRysunek(1);
怎么能用bit类型呢,那就是最多一个字节来描述。image,应该使用oid。那什么时候用bit??