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 7566513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:26:04+00:00 2026-05-30T14:26:04+00:00

I need to retrieve some data stored as varchar in an SQL table to

  • 0

I need to retrieve some data stored as varchar in an SQL table to bytes[] in c#.

The SQL server is running MS SQLServer 2005.
The table in question has a column defined as varchar(3900), non null.
This column is usually filled by c++ code writing different POD structures straight into the column.
Basically passing the pointer to the structure to the c++ sql code updating the table.
Different c++ programs read and write to this table and share the same headers describing those POD structures.
The type of POD structure is indicated by another column in the table. Lets call it DataType
The way the table is defined (as the column) cannot be changed. It would require a way to huge change in the currently functioning systems.

How can I get the full content (the 3900 bytes) of the varchar to Bytes[] in C#
My aim is use ADO.net to get rows from this table. Read this column and the DataType one.
Depending on DataType build an Object following the skeleton of the c++ POD structure.

Then how to write back to the table from my C# Object to the varchar(3900).

I read this question but it seems ADO.net sees this column as string and then truncate the content. I cannot seem to get the “raw” content of the varchar column.

Any idea?

Edit:

In c++
The data written to the column is declared as a char[3901].
Complete POD structures are “written” over it using memcopy.
Before being stored in the table using ADO:
It is first converted to a WideCharString using MultiByteToWideChar
Then to a Bstring BSTR which in turn is put into a VARIANT and finaly used by ADO to update the table.

  • 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-30T14:26:05+00:00Added an answer on May 30, 2026 at 2:26 pm

    Given a table

    create table foobar
    (
      id        int           not null primary key ,
      some_text varchar(2000) not null ,
    )
    

    To retrieve some_text as octets:

    select id = id ,
           some_octets = convert(varbinary(2000),some_text)
    from foobar
    

    An insert and update:

    declare @id          int
    declare @some_octets varbinary(2000)
    
    insert foobar ( id , some_text ) values ( @id , convert(varchar(2000),@some_octets) )
    
    update foobar set @some_text = convert(varchar(2000),@some_octets)
    where id = @id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve random rows from SQL Server database. I am looking for
Essentially I need to retrieve some account information from the dbase table where they
Need to store some data in window.load and retrieve in document.ready : <script> $(window).load(function()
I need to retrieve all rows from a table where 2 columns combined are
I need to retrieve a set of Widgets from my data access layer, grouped
I need to retrieve the name of the stored procedure that a crystal report
I need to retrieve data from two tables. the first is a list of
I need to retrieve records that match IDs stored in a list. The query,
I'm looking to retrieve some data from MongoDB but I'm unsure of how to
I'm building a system that need to collect some user sensitive data via secured

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.