Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get to retrieve Bytes[] from VARCHAR in Ado.Net?
    primarykey
    data
    text
    <p>I need to retrieve some data stored as varchar in an SQL table to bytes[] in c#.</p> <p>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.</p> <p>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.</p> <p>Then how to write back to the table from my C# Object to the varchar(3900).</p> <p>I read this <a href="https://stackoverflow.com/questions/2553285/how-to-get-varchar-as-byte-using-datareader-in-ado-net">question</a> 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.</p> <p>Any idea?</p> <p>Edit:</p> <p>In c++ The data written to the column is declared as a <code>char[3901]</code>. Complete POD structures are "written" over it using <code>memcopy</code>. Before being stored in the table using ADO: It is first converted to a WideCharString using <code>MultiByteToWideChar</code> Then to a Bstring <code>BSTR</code> which in turn is put into a <code>VARIANT</code> and finaly used by ADO to update the table.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload