devxlogo

Save Data in a SQL Server Image Column with VB6

Save Data in a SQL Server Image Column with VB6

I needed to retrieve image fields on SQL Server 7.0 with VB6, and I couldn’t find any article about it. So, I assume others have had the same problem. I’ve since found a method for doing it.

You must use Microsoft ADO 2.5 and set it into the following project reference:

 dim rst as new adodb.recordsetdim adoConn as new adodb.Connection

You also have to open the connection with the database.

 'Open recordset....rst.Open "Select * from 
where ", adoConn, adOpenKeyset,adLockOptimistic'THIS FUNCTION SAVES AN IMAGE
INTO AN IMAGE DATATYPE FIELDPrivate Function SaveImage() Dim mStream As New ADODB.Stream With mStream .Type = adTypeBinary .Open .LoadFromFile "NAME>" rst("").
Value = .Read rst.Update End With Set mStream = NothingEnd Function'THIS FUNCTION LOAD IMAGE FROM
IMAGE DATATYPE FIELD AND SAVE IT INTO AFILE.....Private Function LoadImage() Dim mStream As New ADODB.Stream With mStream .Type = adTypeBinary .Open .Write rst("") .SaveToFile "NAME>", adSaveCreateOverWrite End With Set mStream = NothingEnd Function

Aside from this method, you can use a picture control to store an image,put a picture control into a form, and call it PictureTemp.

 PictureTemp.DataField = "Immagine"			
'Set DataField....Set PictureTemp.DataSource = rst
'Set DataSource

You can use the PictureTemp.Picture property to get your image.

 Private Function LoadImage()  Dim mStream As New ADODB.Stream  With mStream    .Type = adTypeBinary    .Open    PictureTemp.DataField = "Immagine"			
'Set DataField.... Set PictureTemp.DataSource = rst
'Set DataSource Set MSFGRID.CellPicture = PictureTemp.Picture
'Show image into a cell ofMicrosoft FlexGrid End With Set mStream = NothingEndFunction
See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist

©2024 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.