Example Code

Inserting an image into a database without the size of the data appended

Code and Documents

Attachment

Introduction

Normally when using the Database Connectivity Toolkit to insert an image into a database, 4 bytes will be appended to the front of the data to show the size of it.  This works fine with LabVIEW because data like that is stored with this information normally.  However, if a third-party program wants to interact with this data, some extra work can be necessary to remove that information.  This example shows how to insert the data without the extra bytes.

Steps to Complete

1. Open a connection to the database.

2. Read the image from a file into an array of bytes.

3. Convert the bytes into a string of hex values.

4. Insert the hex string into an insert statement (INSERT INTO TableName VALUES (0xFFFAA...);).

5. Execute the insert statement and clean up the connection.

InsertImageDBExample.png

Jared S.
Applications Engineering
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Nitin_Bhandari
Member
Member
on

This InsertImageDB Example VI is not working for my image. I am getting error while executing the query. Please help in this regard. I have also inserted my query in the Discussion Forums. http://forums.ni.com/t5/LabVIEW/how-to-store-jpeg-images-in-SQL-server-using-NI-database/td-p/223944...

Error.JPG

Contributors