Article View: borland.public.cppbuilder.database.dbexpress
Article #188Re: TSQLQuery - ParamByName and the AsDateTime
From: Nicholas Hugh
Date: Fri, 21 Mar 2008 14:09
Date: Fri, 21 Mar 2008 14:09
92 lines
4489 bytes
4489 bytes
try
ParmByName("paramNameToSet")->AsDate = aDateTimeObject, ie
AsDateTime ->AsDate
"Ned" <nemanada@yahoo.com> wrote in message
news:4799437b$1@newsgroups.borland.com...
> Hi,
>
> Not sure if this has been covered anywhere in the newsgroups. Couldn't see
> anything. I spent the last day trying to see why a number of BCB 6 project
> we had no longer work when the parameters are set in a query.
>
> I found that calling ParmByName("paramNameToSet")->AsDateTime =
> aDateTimeObject, did not actually set the parameter when ExecSQL is
> called. The parameter appears to be set when you check it but it is not
> passed to the SQL Server. The error shown is
>
> ... raised exception class EDatabaseError with message 'No Value for
> parameter 'pEndDate".
>
> I am using SQL Server 2005 and the enterprise supplied DBExpress
> dbxmss30.dll driver.
>
> It all works if the aDateTimeObject above is converted to an AnsiString
> and the AsDateTime call is replaced with AsString. Both options shown
> below in code.
>
>
> //---------------------------------------------------------------------------
>
> #include <vcl.h>
> #pragma hdrstop
>
> #include "DatabaseAccess.h"
> //---------------------------------------------------------------------------
> #pragma package(smart_init)
> #pragma resource "*.dfm"
> #define USE_TDATETIME
>
> TForm1 *Form1;
> //---------------------------------------------------------------------------
> __fastcall TForm1::TForm1(TComponent* Owner)
> : TForm(Owner)
> {
> }
> //---------------------------------------------------------------------------
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
> //
> // Connect to the database using the built in SQL Enterprise driver
> //
> dbProduction->ConnectionName = "MSSQLConnection";
> dbProduction->DriverName = "MSSQL";
> dbProduction->LoginPrompt = false;
> dbProduction->GetDriverFunc = "getSQLDriverMSSQL";
> dbProduction->LibraryName = "dbxmss30.dll";
> dbProduction->VendorLib = "oledb";
> dbProduction->Params->Add("HostName=");
> dbProduction->Params->Values["HostName"] = "SQLExpress\\SQLExpress";
> dbProduction->Params->Values["User_Name"] = "userName";
> dbProduction->Params->Values["Password"] = "password";
> dbProduction->Params->Values["DataBase"] = "Orders";
> dbProduction->Open();
> //
> // Test the query operation with TDateTime
> //
> AnsiString sParam[5];
> float fParam[5];
> TDateTime currentTime(Now());
> AnsiString endDate;
> AnsiString startDate;
>
> endDate = AnsiString(currentTime.DateTimeString());
> startDate = AnsiString(currentTime.DateTimeString());
>
> #ifdef USE_TDATETIME
> qryAddProduction->Prepared = true;
> qryAddProduction->ParamByName("pEndDate")->AsDateTime = currentTime;
> qryAddProduction->ParamByName("pStartDate")->AsDateTime = currentTime;
> #else
> qryAddProduction->ParamByName("pEndDate")->AsString = endDate;
> qryAddProduction->ParamByName("pStartDate")->AsString = startDate;
> #endif
>
> qryAddProduction->ParamByName("pOrderNo")->AsString = "99999";
> qryAddProduction->ParamByName("pInputOrderNo")->AsString = "99999";
> qryAddProduction->ParamByName("pCompleted")->AsInteger = false;
> qryAddProduction->ExecSQL();
> }
> //---------------------------------------------------------------------------
Technical Details
Message-ID:
<47e3c198@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<4799437b$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: fb4e2,165e6b8d6551d94c X-Google-Attributes: gidfb4e2,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Nicholas Hugh" <nhugh@bigpond.net.au> Newsgroups: borland.public.cppbuilder.database.dbexpress References: <4799437b$1@newsgroups.borland.com> In-Reply-To: <4799437b$1@newsgroups.borland.com> Subject: Re: TSQLQuery - ParamByName and the AsDateTime Date: Sat, 22 Mar 2008 01:09:09 +1100 Lines: 93 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6000.16480 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16545 NNTP-Posting-Host: 124.189.96.117 Message-ID: <47e3c198@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1206108568 124.189.96.117 (21 Mar 2008 07:09:28 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail