dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlDataReader Class / GetMySqlBlob Method / GetMySqlBlob(Int32) Method
The zero-based column ordinal.
Example

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

    Parameters

    i
    The zero-based column ordinal.

    Return Value

    The value of the specified column as a MySqlBlob object.
    Example
    This example shows how to download a BLOB field from a table using GetMySqlBlob method.
    public void DownloadBlob(MySqlConnection myConnection)
    {
      MySqlCommand myCommand = new MySqlCommand("SELECT * FROM Test.Pictures", myConnection);
      myConnection.Open();
      MySqlDataReader myReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default);
      try
      {
        while (myReader.Read())
        {
          MySqlBlob myBlob = myReader.GetMySqlBlob(myReader.GetOrdinal("Picture"));
          if(!myBlob.IsNull)
          {
            string FN = myReader.GetString(myReader.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
      {
        myReader.Close();
        myConnection.Close();
      }
    }
    Public Sub DownloadBlob(ByVal myConnection As MySqlConnection)
      Dim myCommand As New MySqlCommand("SELECT * FROM Test.Pictures", myConnection)
      myConnection.Open()
      Dim myReader As MySqlDataReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default)
      Try
        While myReader.Read()
          Dim myBlob As MySqlBlob = myReader.GetMySqlBlob(myReader.GetOrdinal("Picture"))
          If Not myBlob.IsNull Then
            Dim FN As String = myReader.GetString(myReader.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
        myReader.Close()
        myConnection.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