GetMySqlBlob(Int32) Method
Gets the value of the specified column as a
MySqlBlob object.
|
|---|
'Declaration
Public Overloads Function GetMySqlBlob( _
ByVal As Integer _
) As MySqlBlob |
Parameters
- i
- The zero-based column ordinal.
Return Value
The value of the specified column as a
MySqlBlob object.
This example shows how to download a BLOB field from a table using
GetMySqlBlob method.
|
|---|
public void DownloadBlob(MySqlConnection mySqlConnection)
{
MySqlCommand mySqlCommand = new MySqlCommand("SELECT * FROM Test.Pictures", mySqlConnection);
mySqlConnection.Open();
MySqlDataReader mySqlReader = mySqlCommand.ExecuteReader(System.Data.CommandBehavior.Default);
try
{
while (mySqlReader.Read())
{
MySqlBlob myBlob = mySqlReader.GetMySqlBlob(mySqlReader.GetOrdinal("Picture"));
if(!myBlob.IsNull)
{
string FN = mySqlReader.GetString(mySqlReader.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
{
mySqlReader.Close();
mySqlConnection.Close();
}
} |
|
|---|
Public Sub DownloadBlob(ByVal mySqlConnection As MySqlConnection)
Dim mySqlCommand As New MySqlCommand("SELECT * FROM Test.Pictures", mySqlConnection)
mySqlConnection.Open()
Dim mySqlReader As MySqlDataReader = mySqlCommand.ExecuteReader(System.Data.CommandBehavior.Default)
Try
While mySqlReader.Read()
Dim myBlob As MySqlBlob = mySqlReader.GetMySqlBlob(mySqlReader.GetOrdinal("Picture"))
If Not myBlob.IsNull Then
Dim FN As String = mySqlReader.GetString(mySqlReader.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
mySqlReader.Close()
mySqlConnection.Close()
End Try
End Sub |