dotConnect for PostgreSQL Documentation
Devart.Data.PostgreSql Namespace / PgSqlDataReader Class / GetPgSqlBlob Method / GetPgSqlBlob(Int32) Method
The zero-based column ordinal.
Example

In This Topic
    GetPgSqlBlob(Int32) Method
    In This Topic
    Gets the value of the specified column as a PgSqlBlob object.
    Syntax
    'Declaration
     
    Public Overloads Function GetPgSqlBlob( _
       ByVal i As Integer _
    ) As PgSqlBlob
    public PgSqlBlob GetPgSqlBlob( 
       int i
    )

    Parameters

    i
    The zero-based column ordinal.

    Return Value

    The value of the specified column as a PgSqlBlob object.
    Example
    This example shows how to download a BLOB field from a table using GetPgSqlBlob method.
    public void DownloadBlob(PgSqlConnection pgConnection)
    {
      PgSqlCommand pgCommand = new PgSqlCommand("SELECT * FROM Test.Pictures", pgConnection);
      pgConnection.Open();
      PgSqlDataReader pgReader = pgCommand.ExecuteReader(System.Data.CommandBehavior.Default);
      try
      {
        while (pgReader.Read())
        {
          PgSqlBlob myBlob = pgReader.GetPgSqlBlob(pgReader.GetOrdinal("Picture"));
          if(!myBlob.IsNull)
          {
            string FN = pgReader.GetString(pgReader.GetOrdinal("PicName"));
            FileStream fs = new FileStream("D:\\Tmp\\"+FN+".bmp", FileMode.Create);
            BinaryWriter w = new BinaryWriter(fs);
            w.Write(myBlob.Value);
            w.Close();
            fs.Close();
            Console.WriteLine(FN+" downloaded.");
          }
        }
      }
      finally
      {
        pgReader.Close();
        pgConnection.Close();
      }
    }
    Public Sub DownloadBlob(ByVal pgConnection As PgSqlConnection)
      Dim pgCommand As New PgSqlCommand("SELECT * FROM Test.Pictures", pgConnection)
      pgConnection.Open()
      Dim pgReader As PgSqlDataReader = pgCommand.ExecuteReader(System.Data.CommandBehavior.Default)
      Try
        While pgReader.Read()
          Dim myBlob As PgSqlBlob = pgReader.GetPgSqlBlob(pgReader.GetOrdinal("Picture"))
          If Not myBlob.IsNull Then
            Dim FN As String = pgReader.GetString(pgReader.GetOrdinal("PicName"))
            Dim fs As FileStream = New FileStream("D:\Tmp\" + FN + ".bmp", FileMode.Create)
            Dim w As BinaryWriter = New BinaryWriter(fs)
            w.Write(myBlob.Value)
            w.Close()
            fs.Close()
            Console.WriteLine(String.Concat(FN, " downloaded."))
          End If
        End While
      Finally
        pgReader.Close()
        pgConnection.Close()
      End Try
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also