Inquiridor
C# postgressqql - nao consigo buscar a imagem

Pergunta
-
NpgsqlConnection connPos = Connections.getPostgreSQLConnection(ConfigurationSettings.AppSettings["host"], ConfigurationSettings.AppSettings["port"], ConfigurationSettings.AppSettings["database"], ConfigurationSettings.AppSettings["user"], ConfigurationSettings.AppSettings["pass"]);connPos.Open();
// int e = 1;
// LargeObjectManager lbm = new LargeObjectManager(connPos);
// LargeObject lo = lbm.Open(takeOID(e), LargeObjectManager.READWRITE); //take picture oid from metod takeOID
NpgsqlCommand comando = new Npgsql.NpgsqlCommand();
string tt ="rwerw";
comando.CommandText =
"select lo_export (picture, 'C:\\users\\TEMP\\testeee.jpg') from picture where person='402881d01bdf7413011bdf85ee900002'";
comando.Connection = connPos;
Vitor
Todas as Respostas
-
Vitor,
Aparece algum erro? Preste atenção pois o caminho que você escolheu para exportar o BLOB refere-se à pasta do servidor de banco de dados, ou seja, você solicitou que a imagem fosse salva na pasta C:\users\temp\ do servidor.
Att.
Ari C. Raimundo -
-
-
-
pessoal não estou a conseguir correr este codigo?
HELP
using System;
using Npgsql;
using NpgsqlTypes;
using System.Drawing;
using System.IO;
//metod whos take picture oid from database
public 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 type
public 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 metod
pictureBox1.Image = Image pobierzRysunek(1);
Vitor