[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 817
  • Last Modified:

Adding image to mysql database from vb.net


I have a field in my mysql database as longblob which is meant to store images  of the product. The problem now is I want to store image to this filed from the picturebox. Can somebody give me working code to do the same. As well as how I can retrieve the image and display in the picturebox. I want this code to be working for Visual Basic .net application version 2005. I got a lot of code for PHP and ASP.net but not a single code for vb. please help. its urgent.
DROP TABLE IF EXISTS `imint_new`.`tbl_products`;
CREATE TABLE  `imint_new`.`tbl_products` (
  `p_code` varchar(15) NOT NULL,
  `p_name` varchar(45) NOT NULL,
  `p_mrp` decimal(9,2) NOT NULL,
  `p_cost` decimal(9,2) NOT NULL,
  `p_courier` decimal(7,2) DEFAULT NULL,
  `p_weight` decimal(6,3) NOT NULL,
  `p_dispatch` tinyint(1) unsigned NOT NULL,
  `p_image` longblob,
  `p_active` tinyint(1) unsigned NOT NULL,
  PRIMARY KEY (`p_code`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='A table giving description of the products';

Open in new window

  • 2
1 Solution
Praveen VenuCommented:
kewlchap_85Author Commented:
this does not work. inserts NULL value. Have tried it.
kewlchap_85Author Commented:

I got the solution:

For Insert-

Mysql has an inbuilt function load_file('c:/bc.jpg')

For read-

conn.ConnectionString = My.Settings.conn_str
            str = "select p_image from tbl_products where p_code='SDH'"
            mycom.Connection = conn
            mycom.CommandText = str
            b = mycom.ExecuteScalar()
            If (b.Length > 0) Then
                Dim stream As New MemoryStream(b, True)
                stream.Write(b, 0, b.Length)
                PictureBox1.Image = New Bitmap(stream)
            End If
        Catch ex As Exception
        End Try

Open in new window


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now