473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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
ADODB.
So far, I have managed to store a record but not any data in the binary
field.
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
site
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;
HRESULT hr;
ExakteZeit Zeit;
SatzStruct Satz;

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

CoInitialize(NULL);
try
{
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);
}
catch(...)
{
std::cerr << "Connect to database Exception";
}
}

void DatensatzSchreiben(short ModulNr) {

try {
recordset->AddNew();
recordset->Fields->GetItem(L"Tmod4")->PutValue(varChunk);
recordset->Fields->GetItem(L"UGenIst")->PutValue(mstream->Read(AnzMesswert
e));

recordset->Update();
}

catch(...)
{
std::cerr << "Update Exception";
}
}

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

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

UCHAR chData;
SAFEARRAY FAR *psa;
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);
index1++;
}

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

mstream->Write(varChunk);

DatensatzSchreiben(1);
recordset->Close();
connection->Close();
return 0;

}
Jul 23 '05 #1
0 2456

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

Similar topics

3
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...
6
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...
3
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"...
1
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...
3
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...
0
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...
6
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...
0
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...
0
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. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.