Send and Recieve binary data

Send and Recieve binary data

Postby Duane » 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?
Duane
 
Posts: 3
Joined: Wed 29 Mar 2006 20:41

Postby Alexey » Thu 30 Mar 2006 09:41

Yes.
Please refer to MySqlBlob class for more information on how to send and recieve blobs from a database.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Duane » Thu 30 Mar 2006 20:02

Ummm I thought this was the PostgreSQLDirect.NET forum not the MySQLDirect .NET form. So are you saying I can use the MySQL methods (like GetMySqlBlob)?
Duane
 
Posts: 3
Joined: Wed 29 Mar 2006 20:41

Postby Alexey » Fri 31 Mar 2006 06:12

If we are talking about PostgreSQL database, use PostgreSQLDirect .NET PgSqlBlob class.
Hopefully, this code snippet will be of help:
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();
      }
    }
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43

Postby Duane » Fri 31 Mar 2006 15:37

That code looks interesting, is that C# code?
Duane
 
Posts: 3
Joined: Wed 29 Mar 2006 20:41

Postby Alexey » Mon 03 Apr 2006 06:24

Yes. This is all C#.
Alexey
 
Posts: 2756
Joined: Mon 13 Mar 2006 07:43


Return to dotConnect for PostgreSQL