BLOB Data retrieval in table form

256 Views Asked by At
MySqlConnection con= new MySqlConnection("server=localhost;database=databasename;user=username;password=password");

string query="select *from table";

using (MySqlDataAdapter adpt= new MySqlDataAdapter(query,con))
{

DataSet dset= new DataSet();

adpt.Fill(dset);

mytableDataGridView.DataSource=dset.Tables[0];

}
con.close

the following code can only retrieve data of varchar and int, don't retrieve BLOB kind of data ....plzz give a solution so that blob can be read by this method or any other method with downloadable file mode

1

There are 1 best solutions below

0
On

The Blob data should be read from the database into a byte array. Something like this should do it:

FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);   
byte[] photo = br.ReadBytes((int)fs.Length);    
br.Close();
fs.Close();

I took the code from here: https://www.akadia.com/services/dotnet_read_write_blob.html. Note that you could load the BLOB into a memory stream instead of a filestream if you wanted to simply display the BLOB on the screen e.g. if it is a photo.