473,832 Members | 2,137 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 2481

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

Similar topics

3
11773
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
5713
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
6192
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
1559
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
10693
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
12091
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
3206
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
1548
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
1346
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
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10499
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
10541
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
10212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7753
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
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4421
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
3078
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.