Thread View: borland.public.cppbuilder.database.ado
1 messages
1 total messages
Started by Kevin Hackney
Tue, 23 Oct 2007 20:37
How to pass a data structure to a stored procedure via ADO
Author: Kevin Hackney
Date: Tue, 23 Oct 2007 20:37
Date: Tue, 23 Oct 2007 20:37
104 lines
4275 bytes
4275 bytes
Can anyone tell me how to pass a data structure such as the following
typedef struct{
bool Sensor1;
bool Sensor2;
bool Sensor3;
bool Sensor4;
} SmartCardType;
in binary to a stored procedure using either a TADODataSet or
TADOStoredProc? I need to store a data structure in a binary() field in
a SQL Server 2005 database by updating the record from a stored procedure in
Borland C++. I've been trying to use TMemoryStream but when I run this code
I get the following error: EOleException with message 'Application uses a
value of the wrong type for the current operation'. Below is the function
I'm trying to get working:
bool __fastcall SaveInfoDB::SetAllValues(bool Infinite, bool NoSleep, short
LocationID, bool PassedMemoryTest, bool FirmwareLoaded, bool Heartbeat, char
*DebugString, SmartCardType *CardData)
{
try
{
bool ReturnValue;
char StoredProcedure[25];
strcpy(StoredProcedure, "srpSetSmartCardSaveInfo");
TADOConnection *adoSetConn;
TADODataSet *adoUpdDataSet;
TMemoryStream *memStream;
memStream = new TMemoryStream();
adoUpdDataSet = new TADODataSet(NULL);
memStream->Write(CardData, sizeof(CardData));
ReturnValue = False;
ReturnValue = GetSetValue::PrepUpdateDataset(Infinite, NoSleep,
&adoSetConn, &adoUpdDataSet, StoredProcedure);
if (ReturnValue == True)
{
//Define stored procedure paramaters
adoUpdDataSet->Parameters->CreateParameter("@RETURN_VALUE", ftInteger,
pdReturnValue, sizeof(ftInteger), NULL);
adoUpdDataSet->Parameters->CreateParameter("@LocationID", ftSmallint,
pdInput, sizeof(ftSmallint), LocationID);
adoUpdDataSet->Parameters->CreateParameter("@PassedMemoryTest",
ftBoolean, pdInput, sizeof(ftBoolean), PassedMemoryTest);
adoUpdDataSet->Parameters->CreateParameter("@FirmwareLoaded", ftBoolean,
pdInput, sizeof(ftBoolean), FirmwareLoaded);
adoUpdDataSet->Parameters->CreateParameter("@Heartbeat", ftBoolean,
pdInput, sizeof(ftBoolean), Heartbeat);
adoUpdDataSet->Parameters->CreateParameter("@DebugString", ftString,
pdInput, 25, DebugString);
adoUpdDataSet->Parameters->CreateParameter("@CardData", ftBytes, pdInput,
2048, NULL);
adoUpdDataSet->Parameters->ParamByName("@CardData")->LoadFromStream(memStream,
ftBytes);
adoSetConn->Connected = True;
adoUpdDataSet->Active = True;
adoUpdDataSet->Post();
if (adoUpdDataSet->Parameters->ParamByName("@RETURN_VALUE")->Value >= 1)
{
ReturnValue = True;
}
else
{
ReturnValue = False;
}
//Close the connection and dataset.
adoUpdDataSet->Active = False;
ReleaseThreadSafeDBConn(adoSetConn);
delete memStream;
delete adoUpdDataSet;
}
return ReturnValue;
}
catch (Exception& e)
{
Globals->Utility->MyCatch(&e,"SaveInfoDB::SetAllValues");
}
return False;
-------------------------------------------------------------------
Below are the parameters as defined in the stored procedure:
CREATE PROCEDURE [dbo].[srpSetSmartCardSaveInfo]
@LocationID AS SMALLINT,
@PassedMemoryTest AS BIT,
@FirmwareLoaded AS BIT,
@Heartbeat AS BIT,
@DebugString AS VARCHAR(25),
@CardData AS BINARY(2048)
Any assistance would be greatly appreciated.
Thanks,
Kevin
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads