How i save Picture 'BMP File' in Sql Server Image Field, Plz send me full Code in VB.6

Dani AI

Generated

Short answer: treat the image as raw bytes in VB6, send those bytes to SQL Server with a properly typed parameter, and avoid the legacy IMAGE pitfalls. The replies from and point in the right direction; below are VB6-specific notes, a compact pattern you can adapt, and a couple of common gotchas.

A few design choices to consider first: either keep files on disk and store paths in the database, or store the bytes in the database (prefer modern column types such as varbinary(max) or use FILESTREAM for very large files). See Microsoft documentation for varbinary for the recommended server-side type: .

VB6 pattern (reliable for BMP files)

  • Use ADODB.Stream to load the .bmp file as binary.
  • Use an ADODB.Command with a parameter for the image (binary parameter) and pass the stream data.
  • Keep parameters typed (e.g., adLongVarBinary/adVarBinary) and set the size where needed.

Example (compact VB6 sketch):

Dim stm As New ADODB.Stream
stm.Type = adTypeBinary
stm.Open
stm.LoadFromFile "C:\path\image.bmp"
Dim imgBytes() As Byte
imgBytes = stm.Read
stm.Close

Dim cmd As New ADODB.Command
Set cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO MyTable (Id, ImgData) VALUES (?, ?)"
cmd.CommandType = adCmdText
cmd.Parameters.Append cmd.CreateParameter("Id", adInteger, adParamInput, , 1)
cmd.Parameters.Append cmd.CreateParameter("Img", adLongVarBinary, adParamInput, UBound(imgBytes) + 1, imgBytes)
cmd.Execute

Important gotchas

  • VB6/OLE wrappers: images copied from OLE containers may include an OLE header. If a retrieved blob does not display, search for the BMP signature ("BM" / 0x42 0x4D) in the byte stream and extract from that offset.
  • Test with small files first, confirm provider (SQLOLEDB vs SQL Native Client), and check parameter sizes and cursor settings if inserts fail.

If posting code for help, include the exact DB column definition, the connection string, and the VB6 snippet you tried — that will make debugging much faster than asking for full code up front (as suggested).

Recommended Answers

All 2 Replies

Not that I have done this but I read somewhere in some forum that you should change the image field to a binary field and load the binary data into it.

Now, as for asking for full code, that is one of the fastest ways in which to have your thread ignored by anyone who might have been willing to help you. It is just a turn off. How about you try and figure it out and post what code you have.


Good Luck

commented: Well said! +36
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.