473,770 Members | 5,842 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\G emeinsame 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::_Connect ionPtr connection;
ADODB::_Records etPtr recordset;
ADODB::_StreamP tr mstream;
_variant_t varChunk;
void ConnectDB(void) {

CoInitialize(NU LL);
try
{
hr = connection.Crea teInstance(__uu idof(ADODB::Con nection));
if (FAILED(hr)) throw _com_error(hr);
hr = recordset.Creat eInstance(__uui dof(ADODB::Reco rdset));
if (FAILED(hr)) throw _com_error(hr);
connection->CursorLocati on = ADODB::adUseCli ent;
connection->Open(L"Provide r=sqloledb;Data Source=localhos t;"
L"Initial Catalog=Modulme ssdaten;User Id=sa;Password= <Passwort>;", L"",
L"", ADODB::adConnec tUnspecified);
recordset->Open(L"Messdat en", connection.GetI nterfacePtr(),
ADODB::adOpenDy namic, ADODB::adLockOp timistic, ADODB::adCmdTab le);
}
catch(...)
{
std::cerr << "Connect to database Exception";
}
}

void DatensatzSchrei ben(short ModulNr) {

try {
recordset->AddNew();
recordset->Fields->GetItem(L"Tmod 4")->PutValue(varCh unk);
recordset->Fields->GetItem(L"UGen Ist")->PutValue(mstre am->Read(AnzMesswe rt
e));

recordset->Update();
}

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

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

hr = mstream.CreateI nstance(__uuido f(ADODB::Stream ));
if (FAILED(hr)) throw _com_error(hr);
mstream->Type = ADODB::adTypeBi nary;

UCHAR chData;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = AnzMesswerte;
psa = SafeArrayCreate (VT_UI2,1,rgsab ound);
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 = SafeArrayPutEle ment(psa,&index 1,&chData);
index1++;
}

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

mstream->Write(varChunk );

DatensatzSchrei ben(1);
recordset->Close();
connection->Close();
return 0;

}
Jul 23 '05 #1
0 2478

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

Similar topics

3
11763
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
6
5706
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 (INT, auto_increment), an ORDER field (INT, for knowing the right order) and a "normal" BLOB field. It is planned to split large files in 64k-parts and sort these parts by the ORDER field. Here's some pseudo code how I wanted to implement this...
3
6189
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" name="UpFileName" STYLE="{Width:400px}"><BR>
1
1557
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 vb.net to populate a sql table. I want to store both string and binary data.
3
10659
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 using $_FILES. What I dont know is how to to them store the image in a database. Can someone please supply the code required to do this? Also, what is the SQL code needed to CREATE the database? I have in the past done this by storing the images...
0
12087
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 likelihood of CRM success from less than 20 percent to 60 percent. WHITEPAPER :
6
3199
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 me like there were performance issues at the time. How about the different types? The MS docs I would expect Access to differentiate and handle appropriately (i.e. .DOC and .XLS).. but how about ..PDF? and can I stash a .TXT document in the...
0
1545
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 that. Any sugguestion? --------------------------------------------------------------------------- import win32com.client as wc
0
1343
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. username = form.get("username", "") message = form.get("message", "") attachment = form.get("attachment", None) .... c.execute("""INSERT INTO Message (username, message, attachment) VALUES (%s, %s, %s)""", (username, message, attachment))
0
10225
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.