Adding image to mysql database from

Posted on 2009-02-08
Last Modified: 2012-05-06

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 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

Question by:kewlchap_85
    LVL 15

    Expert Comment

    by:Praveen Venu
    LVL 2

    Author Comment

    this does not work. inserts NULL value. Have tried it.
    LVL 2

    Accepted Solution


    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now