BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SP problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Cenk
Guest





PostPosted: Sat Jul 01, 2006 1:59 pm    Post subject: SP problem Reply with quote



hi,

i have a SP like below;

CREATE Procedure test1
@price as varchar(50),
@table as varchar(50)
AS


Declare @SQL_INS VarChar(1000)


SELECT @SQL_INS = 'select ['+@price+'] from ['+@table+']'

Exec (@SQL_INS)

and i have a code segment like this in BCB;

TStoredProc *Stp;
Stp= new TStoredProc (this);
Stp->DatabaseName = "Raw";

Stp->StoredProcName = "test1";


Stp->Params->Clear();
Stp->ParamByName("price")->AsString = "CLOSE"; -----> Gives ERROR
parameter price NOT FOUND?

Stp->ParamByName("table")->AsString = "MINUTE1(EUR/USD)";

Stp->Open();

for (int i = 0;i<rowtemp ;i++)
{
arr.push_back(Stp->ParamByName(price)->AsFloat);

Stp->Next();
}
What should i do?
Back to top
Leif Suonvieri
Guest





PostPosted: Fri Jul 07, 2006 12:02 am    Post subject: Re: SP problem Reply with quote



Why do you use a stored procedure which contains dynamic SQL?
The SQL command you are trying to execute in the example seems to be
something like:

SELECT [CLOSE] FROM [MINUTE1(EUR/USD)]

Is that correct? Do you really have a table named MINUTE1(EUR/USD) which
contains a field named CLOSE? (sounds a bit odd to me)

Why are you reading the parameter afterwards in the loop?
The SP doesn't modify it, so I don't see the point.

It feels like you've left out some information, or doing it wrong.
How do the table look like (the field defs...)

In a bigger view, what are you trying to accomplish?

I would like more information to be able to help you...

/Leif
Back to top
Leif Suonvieri
Guest





PostPosted: Fri Jul 07, 2006 12:39 am    Post subject: Re: SP problem Reply with quote



I'll give it a try anyway:

I suppose you have to create the parameter(s) by code, since you create
the SP object by code.

use something like:

Stp->Params->CreateParam(ftString, "@price", ptInput);
Stp->Params->CreateParam(ftString, "@table", ptInput);

If I understand your code correctly the result should be availiable as
records in the Stp object.
In that case use something like this to read the records:

Stp->FieldByName("CLOSE")->AsString;
Back to top
Cenk
Guest





PostPosted: Fri Jul 07, 2006 7:25 pm    Post subject: Re: SP problem Reply with quote

I have couple of DBs and tables and user selects whatever one he wants,
thats why i need to use dynamic SQL. The result of my SP will return, lets
say 124 datas as an example. I get those data into a vector, thats not our
issue here.Anyways, i changed the code according to your advises but now i
gives "error creating cursor handle" at Stp->Open (); statement.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.