Reading blob data


Reading the blob data out of MySQL not so hard. The DataTable is filled as usual - and we can access the byte array by just typecasting - (byte[]) row["blobcolumn"];



        public DataTable GetData_MySQLBinary()
        {
            MySql.Data.MySqlClient.MySqlConnection oConn = new MySql.Data.MySqlClient.MySqlConnection();
            oConn.ConnectionString = "Database=sakila;Data Source=192.168.10.4;User id=stefan;Password=pekka";
            oConn.Open();

            DataSet oDataSet = new System.Data.DataSet("tab1");
            //Get data
            MySql.Data.MySqlClient.MySqlCommand command =
                new MySql.Data.MySqlClient.MySqlCommand("select * from cust_file", oConn);

            MySql.Data.MySqlClient.MySqlDataAdapter oAdapter =
                new MySql.Data.MySqlClient.MySqlDataAdapter(command);
            oAdapter.Fill(oDataSet, "tab1");
            DataTable dt = oDataSet.Tables["tab1"];
            oConn.Close();

            return dt;


        }



and to use the blob data inside an Windows Forms picturebox:



                       DataTable dt = GetData_MySQLBinary();
                        if (dt.Rows.Count > 0)
                        {
                            byte[] bData2 = (byte [])dt.Rows[0]["filedata"];
                            System.IO.MemoryStream oStream = new System.IO.MemoryStream(bData2);
                            pictureBox1.Image = Image.FromStream(oStream);
                        }