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

On this page
    GetPgSqlBlob(Int32) Method
    On this page
    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 pgSqlConnection)
    {
      PgSqlCommand pgSqlCommand = new PgSqlCommand("SELECT * FROM Test.Pictures", pgSqlConnection);
      pgSqlConnection.Open();
      PgSqlDataReader pgSqlReader = pgSqlCommand.ExecuteReader(System.Data.CommandBehavior.Default);
      try
      {
        while (pgSqlReader.Read())
        {
          PgSqlBlob myBlob = pgSqlReader.GetPgSqlBlob(pgSqlReader.GetOrdinal("Picture"));
          if(!myBlob.IsNull)
          {
            string FN = pgSqlReader.GetString(pgSqlReader.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
      {
        pgSqlReader.Close();
        pgSqlConnection.Close();
      }
    }
    Public Sub DownloadBlob(ByVal pgSqlConnection As PgSqlConnection)
      Dim pgSqlCommand As New PgSqlCommand("SELECT * FROM Test.Pictures", pgSqlConnection)
      pgSqlConnection.Open()
      Dim pgSqlReader As PgSqlDataReader = pgSqlCommand.ExecuteReader(System.Data.CommandBehavior.Default)
      Try
        While pgSqlReader.Read()
          Dim myBlob As PgSqlBlob = pgSqlReader.GetPgSqlBlob(pgSqlReader.GetOrdinal("Picture"))
          If Not myBlob.IsNull Then
            Dim FN As String = pgSqlReader.GetString(pgSqlReader.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
        pgSqlReader.Close()
        pgSqlConnection.Close()
      End Try
    End Sub
    See Also