Send and Recieve binary data
Posted: Wed 29 Mar 2006 20:43
Can bytea items be sent to and recieved from the database without using a dataset as shown in the "Pictures" sample?
Discussion forums for open issues and questions concerning database tools, data access components and developer tools from Devart
https://forums.devart.com/
Code: Select all
public Bitmap DownloadBlob(PgSqlConnection Connection, string picname)
{
PgSqlCommand Command = new PgSqlCommand("SELECT Picture FROM Test.pgsqlnet_pictures WHERE Name=:picname", Connection);
Command.Parameters.Add("picname", picname);
Connection.Open();
try
{
using (PgSqlDataReader Reader = Command.ExecuteReader())
{
if (Reader.Read())
return new Bitmap(Reader.GetPgSqlBlob(0));
}
}
finally
{
Connection.Close();
}
return null;
}
public void UploadBlob(PgSqlConnection Connection, Bitmap bitmap, string picname)
{
PgSqlBlob myBlob = new PgSqlBlob();
bitmap.Save(myBlob, ImageFormat.Bmp);
PgSqlCommand Command = new PgSqlCommand("INSERT INTO Test.pgsqlnet_pictures (NAME, PICTURE) VALUES(:picname,:picture)", Connection);
Command.Parameters.Add("picname", picname);
Command.Parameters.Add("picture", myBlob);
Connection.Open();
try
{
Console.WriteLine(Command.ExecuteNonQuery() + " rows affected.");
}
finally
{
Connection.Close();
}
}