Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4625452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:16:28+00:00 2026-05-22T03:16:28+00:00

If you have a column of type binary in SQL and return it using

  • 0

If you have a column of type binary in SQL and return it using ADODB in VB6 even if the column contains only 1 byte of data it must be stored as a byte array.

So for example:

Dim cm As ADODB.Command
Dim rs As ADODB.Recordset

Set cm = New ADODB.Command
Set rs = New ADODB.Recordset

With cm
    .ActiveConnection = cn
    .CommandTimeout = 30
    .CommandType = adCmdText
    .CommandText = "SELECT * FROM Table WHERE RowID = ?"
    .Parameters.Append .CreateParameter("TableID", adInteger, adParamInput, , TableID)
End With

RecordsetOpen cn, rs, cm, , adOpenForwardOnly, adLockReadOnly

With rs
    If .State = adStateOpen Then
        If .RecordCount > 0 Then
            Dim tempArray() As Byte
            tempArray = .Fields("BinaryColumn")
            ''Success! Returns array containing 1 Byte in it

            Dim value as Byte
            value = .Fields("BinaryColumn")
            ''Fails! Run-Time error '13' Type Mismatch
        End If
    End If
End With

Allot of people would look at that and say “So what? Its failing with a type mismatch because you have a Byte() and are trying to set a Byte!”.

My argument is Fields.Value is a property of Type Variant and given VB6s liberal policies on typecasting I would have figured something like this would work.

Could someone explain why this fails?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:16:29+00:00Added an answer on May 22, 2026 at 3:16 am

    Even though it’s a variant, it still has the type embedded in it. Please note the image of the VB6 watch window:

    enter image description here

    Even though the expression is a variant, the type inside the variant is still well defined (string in this case). Thus VB can’t just convert a byte array into a byte just because there is only one element in it. The behavior exhibited by your code snippet is perfectly normal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a LINQ to SQL class called Data with a column of type
I have a MySQL DB which stores data into a column of type 'binary'
I'm using MS SQL Server 2008. I have a column of type XML that
I have at my SQL Server 2000 Database a column with type Image .
You may have a bytea column mapped as Hibernate type binary. In java, the
I have a legacy schema that contains tables with primary keys of type binary(16)
Using Postgres. I have users, which have items. Items have a column type. I'm
I have a column of type Bit (called BBoolVal in this example). I have
I am working with a DataGridView and have a column of type DataGridViewComboBox and
i created a FTS by this article i have a column with type of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.