🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

MS Access, Parameters, and BCB6

#628
From: poojo hackma
Date: Wed, 02 Nov 2005 17:49
72 lines
3837 bytes
I keep getting exceptions thrown when I enter information into my database
using parameters because the INSERT statement is not correct.

I'd like to use more Parameters (TParameter), but BCB6 doesn't give an 
example of how to use them.  Regarding TParameter, the Help did not answer 
these questions:
1. I did not see a DataType ftDouble.
   Should I used ftFloat instead?
   Do I enter a Size (for ftString), or leave it zero?
   Do I need to specify NumericScale (digits after decimal)?
   Do I need to specify Precision (total number of digits)?
2. For DataType ftLargeint:
   Should I leave NumericScale = 0?
   How do I determine Precision (total number of digits)?
3. For DataType ftString:
   Do I leave NumericScale and Precision with their default values of 0?
   Do I need to specify Size, or will it fill automatically?

My code below does not include this, but it is giving me the INSERT error:

(int spn;)
{
// For visibility, I broke up the string into multiple sections:
ADOCommand1->CommandText =
  "INSERT INTO Table1 " +
  "  (ID,Desc,Len,Res,Ofs,Min,Max,Unit,Sus,PGN,start) " +
  "VALUES " +
  "  (:pSP,:pDe,:pLe,:pRs,:pOs,:pMn,:pMx,:pUt,:pSp,:pPG,:pBt)";

ADOCommand1->Parameters->ParamByName("pSP")->DataType = ftLargeint;
ADOCommand1->Parameters->ParamByName("pSP")->Value = spn;

ADOCommand1->Parameters->ParamByName("pDe")->DataType = ftString;
ADOCommand1->Parameters->ParamByName("pDe")->Value = spec.desc;

ADOCommand1->Parameters->ParamByName("pLe")->DataType = ftLargeint;
ADOCommand1->Parameters->ParamByName("pLe")->Value = spec.len;

ADOCommand1->Parameters->ParamByName("pRs")->DataType = ftFloat;
ADOCommand1->Parameters->ParamByName("pRs")->Value = spec.res;

ADOCommand1->Parameters->ParamByName("pOs")->DataType = ftFloat;
ADOCommand1->Parameters->ParamByName("pOs")->Value = spec.ofs;

ADOCommand1->Parameters->ParamByName("pMn")->DataType = ftFloat;
ADOCommand1->Parameters->ParamByName("pMn")->Value = spec.min;

ADOCommand1->Parameters->ParamByName("pMx")->DataType = ftFloat;
ADOCommand1->Parameters->ParamByName("pMx")->Value = spec.max;

ADOCommand1->Parameters->ParamByName("pUt")->DataType = ftString;
ADOCommand1->Parameters->ParamByName("pUt")->Value = spec.pUnit;

ADOCommand1->Parameters->ParamByName("pSp")->DataType = ftLargeint;
ADOCommand1->Parameters->ParamByName("pSp")->Value = spec.self;

ADOCommand1->Parameters->ParamByName("pPG")->DataType = ftLargeint;
ADOCommand1->Parameters->ParamByName("pPG")->Value = spec.Group;

ADOCommand1->Parameters->ParamByName("pBt")->DataType = ftLargeint;
ADOCommand1->Parameters->ParamByName("pBt")->Value = spec.bit;

ADOCommand1->Execute();

}

// The spec struct is defined as:
struct {
  int bit, len, PGN, self, xER;
  double res, max, min, ofs, val;
  char *pUnit, desc[50];
} spec;
Technical Details
Message-ID: <4368fc33@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news-out.spamkiller.net!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,2a72c28d53e31d35,start
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "poojo hackma" <poojo.com/mail>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: MS Access, Parameters, and BCB6
Date: Wed, 2 Nov 2005 11:49:43 -0600
Lines: 75
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
X-RFC2646: Format=Flowed; Original
X-Antivirus: avast! (VPS 0544-2, 11/02/2005), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 12.45.133.147
Message-ID: <4368fc33@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1130953779 12.45.133.147 (2 Nov 2005 09:49:39 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news-out.spamkiller.net!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail