472,954 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,954 software developers and data experts.

Storing Data in Binary Field using ADODB

Hello everyone,

I am trying to store data in a binary field of an SQL-Server table using
So far, I have managed to store a record but not any data in the binary
I only get exceptions on various part. I have tried both AppendChunk and
using a stream object.
Unfortunately all the examples I can find in the Net and on the Microsoft
are in VB and don't translate easily into C++.

Does anyone have an example where this is done in C++??
Here is my code if you want to check it it's pretty messy because I've been
trying all kinds of things:
#include <ctime>
#include <stdio.h>
#include <iostream>
#include <string.h>

#import "C:\Programme\Gemeinsame Dateien\System\ado\msado15.dll"
rename("EOF", "ADOEOF")

using namespace std;

#include <windows.h>

const AnzMesswerte = 50;
typedef struct {
unsigned int ZeitStempel;
short Uoc, Isc, Umpp, UdcIst, UausIst, Uiso, Iiso, Tin, Tk, Tmod[5];
short UGenIst[AnzMesswerte];
short IGenIst[AnzMesswerte];
unsigned int ZeitStempelEnde;
} SatzStruct;

typedef struct {
unsigned int sec;
unsigned short us, ms;
} ExakteZeit;

#define MaxRetries 10
#define SatzSize sizeof(Satz)
short retries = 0;
unsigned int temp_int;
unsigned int *int_ptr;
unsigned int sec, usec, usec2;
bool err = false;
ExakteZeit Zeit;
SatzStruct Satz;

ADODB::_ConnectionPtr connection;
ADODB::_RecordsetPtr recordset;
ADODB::_StreamPtr mstream;
_variant_t varChunk;
void ConnectDB(void) {

hr = connection.CreateInstance(__uuidof(ADODB::Connecti on));
if (FAILED(hr)) throw _com_error(hr);
hr = recordset.CreateInstance(__uuidof(ADODB::Recordset ));
if (FAILED(hr)) throw _com_error(hr);
connection->CursorLocation = ADODB::adUseClient;
connection->Open(L"Provider=sqloledb;Data Source=localhost;"
L"Initial Catalog=Modulmessdaten;User Id=sa;Password=<Passwort>;", L"",
L"", ADODB::adConnectUnspecified);
recordset->Open(L"Messdaten", connection.GetInterfacePtr(),
ADODB::adOpenDynamic, ADODB::adLockOptimistic, ADODB::adCmdTable);
std::cerr << "Connect to database Exception";

void DatensatzSchreiben(short ModulNr) {

try {


std::cerr << "Update Exception";

int main() {
int i=1;
string l;
cout << "Connecting to database\n";

hr = mstream.CreateInstance(__uuidof(ADODB::Stream));
if (FAILED(hr)) throw _com_error(hr);
mstream->Type = ADODB::adTypeBinary;

UCHAR chData;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = AnzMesswerte;
psa = SafeArrayCreate(VT_UI2,1,rgsabound);
long index1 = 0;

://Copy the data only into Field.
for(long index=0;index<=(AnzMesswerte-1);index++)
//Take BYTE by BYTE and advance Memory Location
chData = Satz.UGenIst[index];
hr = SafeArrayPutElement(psa,&index1,&chData);

varChunk.vt = VT_ARRAY|VT_UI2;
varChunk.parray = psa;


return 0;

Jul 23 '05 #1
0 2429

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
by: Juergen Gerner | last post by:
Hello Python fans, I'm trying and searching for many days for an acceptable solution... without success. I want to store files in a database using BLOB fields. The database table has an ID field...
by: Roberto | last post by:
I have the following problem: I have the following form client side: <FORM.......> <FORM action="./WZUpload.asp" method="Post" enctype="multipart/form-data" WIDTH=100%> <INPUT Type="file"...
by: Arlyn | last post by:
This may be a stupid question but I can't find an easy answer for what I want to do. I need a blob data field that can store both binary and text data like the sql_variant field. I am using...
by: bissatch | last post by:
Hi, I am wanting to learn how to store images in a postgreSQL database. I have got as far as uploading the file using a file/browse field on an html form and have been able to catch the file...
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
by: lialie | last post by:
Hi~ I would like to save images in OLE field in Microsoft Access. It writes the binary data which read from an JPEG/BMP file. But seems I meet an encoding problem. The following code demos...
by: canistel | last post by:
Hi, I have a little python webservice that I created, and in one of the methods I need to store some binary data that was "posted"... I want to do something like this, but it doesn't work. ...
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.