Article View: borland.public.cppbuilder.database.multi-tier
Article #902Passing a value from a function to a SQL Query statement.
From: Guest
Date: Sun, 31 Dec 2000 01:49
Date: Sun, 31 Dec 2000 01:49
103 lines
3696 bytes
3696 bytes
Hi, Guys when writting a cleint application if I perform a
calculation from say two rows from two different tables from an SQL server
and then have the result outputed back to table. How can I pass the variable
from the function to sql statement in C++ here's my example .
/- C_C is Column from Client table
/- C_F is Column from Finance table
/- f_func is the math function to calculate the interest
/- V_ouputfrmfunc is the output from func
/- %C_C is the attribute variable which is assigned a value from the <
V_ouputfrmfunc >.
//--------------------------------------------------------------------/
#include <vcl.h>
#include <stdlib.h>
#include <iostream.h>
#include <math.h>
#include <stdlib.h>
#pragma hdrstop
//---------------------------------------------------------------------/
#pragma package(smart_init)
//-------------Connecting to a SQL Server -----------------//
Database1->AliasName ="oradb1";
Database1->DataBaseName ="Oracle SQL";
Database1->Params->Values["user name"] = "test1";
Database1->Params->Values["password"] = "test2" ;
/--------------End of Procedure ----------------------------------/
//-----------Create ODBC connection to Tables ----------------- //
TTable* table = new TTable(t_client);
table->DatabaseName = "oradb1"
table->TableName ="client";
TTable* table = new TTable(t_finance);
table->DatabaseName = "oradb1"
table->TableName ="finance";
/--------------End of Procedure ----------------------------------/
/------------extract string var from tables -------------/
string C_C = table->FieldByName('PRINCIPLE')->AsString + ",";
{
double strtod(const char *C_C, char **endptr);
char C_C[80], endptr;
double value;
gets(C_C);
value = strtod(C_C, &endptr);
return 0;
string C_F = table->FieldByName('PERCENTAGE')->AsString + ",";
{
double strtod(const char *C_F, char **endptr);
char C_F[80], endptr;
double value;
gets(C_F);
value = strtod(C_F, &endptr);
return 0;
}
while
/---use atof to convert string to a float -------------/
func f_func(double C_C, double C_F);
{
( C_C * C_F) + C_C
};
/ * %C_C --- is the a place holder for a variable "result from function
mention above"/
/* "V_ouputfrmfunc" Is the actual value from the function.
/--------------- execu sql ------------------------------/
Query1->sql->Clear();
Query1->sql->Add("UPDATE client")
Query1->sql->Add("SET CLOSINGB = <%C_C>, V_ouputfrmfunc ") /* <
how can pass a value from a function return value to query statement ? */
Query1->sql->Add("WHERE 'job' = 'ACCOUNTNUM'; ")
Query1->sql->ExecSQL();
/-------------- End SQL ----------------------------------/
Technical Details
Message-ID:
<3a4e9061_2@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.cs.utwente.nl!newshunter!cosy.sbg.ac.at!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!209.21.20.119Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fcd2b,1b26b47b5cddbca1,start X-Google-Attributes: gidfcd2b,public X-Google-ArrivalTime: 2000-12-30 17:50:47 PST Reply-To: "Guest" <cedwarda@altavista.com> From: "Guest" <cedwarda@altavista.com> Newsgroups: borland.public.cppbuilder.database.multi-tier Subject: Passing a value from a function to a SQL Query statement. Date: Sat, 30 Dec 2000 17:49:27 -0800 Lines: 110 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 209.21.20.119 Message-ID: <3a4e9061_2@dnews> X-Trace: 30 Dec 2000 17:48:17 -0800, 209.21.20.119 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.cs.utwente.nl!newshunter!cosy.sbg.ac.at!news.tele.dk!128.230.129.106!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!bornews.borland.com!dnews!209.21.20.119