🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #133

How to pass a data structure to a stored procedure via ADO

#133
From: Kevin Hackney
Date: Tue, 23 Oct 2007 20:37
104 lines
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
Technical Details
Message-ID: <471e5b9b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,ee617c4069a3a759,start
X-Google-Attributes: gid10698b,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Kevin Hackney" <kevin.hackney@gmail.com>
From: "Kevin Hackney" <kevin.hackney@gmail.com>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: How to pass a data structure to a stored procedure via ADO
Date: Tue, 23 Oct 2007 16:37:53 -0400
Lines: 108
Organization: American Greetings Corporation
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4073
NNTP-Posting-Host: 207.58.192.123
Message-ID: <471e5b9b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1193171867 207.58.192.123 (23 Oct 2007 13:37:47 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail