How to pass a data structure as a stored proc parameter to a varbinary field in SQL Server 2005



Can anyone tell me how to pass the contents of the CardData structure
of type SmartCardType

typedef struct{
bool Sensor1;
bool Sensor2;
bool Sensor3;
bool Sensor4;
} SmartCardType;

to a stored procedure using either a TADODataSet or TADOStoredProc?
I'm trying to update a varbinary(max) field in a SQL Server 2005
database from a stored procedure in Borland C++. I've been trying to
use TADOBlobStream and TBlobField. It doesn't work and I'm not even
sure if that's what I should be using. 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;
TADOBlobStream *adoBlobStream;
TBlobField *MyBlobField;

ReturnValue = False;
adoUpdDataSet = new TADODataSet(NULL);
MyBlobField = new TBlobField(adoUpdDataSet);
adoBlobStream = new TADOBlobStream(MyBlobField, bmReadWrite);

// adoBlobStream = new TADOBlobStream(adoUpdDataSet->Fields-
FieldByName("@CardData"), bmWrite);

ReturnValue = GetSetValue::PrepUpdateDataset(Infinite, NoSleep,
&adoSetConn, &adoUpdDataSet, StoredProcedure);

if (ReturnValue == True)
{
//Define stored procedure paramaters
adoBlobStream->Write(CardData, sizeof(CardData));
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", ftBlob,
pdInput, adoBlobStream->Size, NULL);
adoUpdDataSet->Parameters->ParamByName("@CardData")-
LoadFromStream(adoBlobStream, ftBlob);

adoSetConn->Connected = True;
adoUpdDataSet->Active = True;

if (adoUpdDataSet->Parameters->ParamByName("@RETURN_VALUE")->Value
= 1)
{
ReturnValue = True;
}
else
{
ReturnValue = False;
}

//Close the connection and dataset.
adoUpdDataSet->Active = False;
ReleaseThreadSafeDBConn(adoSetConn);
delete adoBlobStream;
delete MyBlobField;
delete adoUpdDataSet;
}
return ReturnValue;
}
catch (Exception& e)
{
Globals->Utility->MyCatch(&e,"SaveInfoDB::SetAllValues");
}
return False;
}

.



Relevant Pages

  • Error: Failed to convert parameter value from a String to a Byte[]. (Need Help Urgently)
    ... Here is the code for executing stored procedure ExecuteSP() [no ... Object returnValue; ... bool myvar = false; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Output Parameter?
    ... Type is output, not returnvalue. ... whether the UserID supplied by the new record already exists or not. ... stored procedure is 1, it means that the UserID already exists. ... Dim sqlConn As SqlConnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Retrieving the @@IDENTITY value from a SP in VB.Net
    ... Set the direction to .ReturnValue to get the RETURN value. ... See my articles on handling @@Identity and stored procedure parameters. ... >> Dim cn As New SqlConnection ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Problem writing XML files.
    ... What the stored procedure does is, ... > NTEXT/ IMAGE type to write the files but they give me errors which, ... > @ReturnValue as image OUT ... > DECLARE @strVar as varchar ...
    (comp.databases.ms-sqlserver)
  • stored proc RETURN_VALUE.... there it is, I want to use it !!!
    ... Parameters.CreateParameter('meetingCode',ftString, pdInput, 6, ... 'RETURN_VALUE' of the dataset parameter. ... kind of plunks itself there whenever you use a stored procedure... ... component to call a stored procedure that it knows the parameters BUT when I ...
    (borland.public.delphi.database.ado)