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 

Param subs for searchs

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





PostPosted: Fri Oct 08, 2004 9:19 pm    Post subject: Param subs for searchs Reply with quote



I have a TQuery all set up and works fine on showing the entire table. But
when I try subing like this it won't work. Error is "Type mismatch in
expression".
DataModule1->Query1>Close();
DataModule1->Query1->SQL->Clear();
DataModule1->Query1->SQL->Add("select * from CalenderDataBase");
DataModule1->Query1->SQL->Add("where IDNmb = ");
DataModule1->Query1->SQL->Add(ID); // ID is declared as a string
loaded for an TEdit
DataModule1->Query1->Open();
If I hard code say "3467" instead of using the variable then it works fine.
ID is declared as a string. I have another program that does the subing with
no problems at all, the only differance is the field is declared as an
interger. Using DBExplorer I can get the proper display with no problem. I
have even used a 2nd Query and get the same error.


Back to top
Don Locke
Guest





PostPosted: Fri Oct 08, 2004 11:45 pm    Post subject: Re: Param subs for searchs Reply with quote



Try it this way:

DataModule1->Query1>Close();
DataModule1->Query1->SQL->Clear();
DataModule1->Query1->SQL->Add("select * from CalenderDataBase");
DataModule1->Query1->SQL->Add("where IDNmb = :num");
DataModule1->Query1->ParamByName("num")->AsString = ID;
if(!DataModule1->Query1->Prepared)
DataModule1->Query1->Prepare;
DataModule1->Open();

HTH, Don
Back to top
Tom
Guest





PostPosted: Sat Oct 09, 2004 1:28 pm    Post subject: Re: Param subs for searchs Reply with quote



Ok, but why would it work in one program and then not this one. Just
curious.
"Don Locke" <dgnospamlocke (AT) comcast (DOT) net> wrote

Quote:
Try it this way:

DataModule1->Query1>Close();
DataModule1->Query1->SQL->Clear();
DataModule1->Query1->SQL->Add("select * from CalenderDataBase");
DataModule1->Query1->SQL->Add("where IDNmb = :num");
DataModule1->Query1->ParamByName("num")->AsString = ID;
if(!DataModule1->Query1->Prepared)
DataModule1->Query1->Prepare;
DataModule1->Open();

HTH, Don



Back to top
Don Locke
Guest





PostPosted: Sat Oct 09, 2004 2:06 pm    Post subject: Re: Param subs for searchs Reply with quote

I'm surprised that it worked in another program!! Another way is to
create a string with the ID in it:

String sID = "WHERE IDNmb = " +ID;
DataModule1->Query1->SQL->Add(sID);
Don

Tom wrote:
Quote:
Ok, but why would it work in one program and then not this one. Just
curious.
"Don Locke" <dgnospamlocke (AT) comcast (DOT) net> wrote in message
news:4167268b$1 (AT) newsgroups (DOT) borland.com...

Try it this way:

DataModule1->Query1>Close();
DataModule1->Query1->SQL->Clear();
DataModule1->Query1->SQL->Add("select * from CalenderDataBase");
DataModule1->Query1->SQL->Add("where IDNmb = :num");
DataModule1->Query1->ParamByName("num")->AsString = ID;
if(!DataModule1->Query1->Prepared)
DataModule1->Query1->Prepare;
DataModule1->Open();

HTH, Don




Back to top
Tom
Guest





PostPosted: Sat Oct 09, 2004 3:37 pm    Post subject: Re: Param subs for searchs Reply with quote

Its working in another program I have, I don't remember where I got the
example for it but it works, and what you gave me does the job so I guess I
need to do some more reserch on my other program. Thanks

"Don Locke" <dgnospamlocke (AT) comcast (DOT) net> wrote

Quote:
I'm surprised that it worked in another program!! Another way is to create
a string with the ID in it:

String sID = "WHERE IDNmb = " +ID;
DataModule1->Query1->SQL->Add(sID);
Don

Tom wrote:
Ok, but why would it work in one program and then not this one. Just
curious.
"Don Locke" <dgnospamlocke (AT) comcast (DOT) net> wrote in message
news:4167268b$1 (AT) newsgroups (DOT) borland.com...

Try it this way:

DataModule1->Query1>Close();
DataModule1->Query1->SQL->Clear();
DataModule1->Query1->SQL->Add("select * from CalenderDataBase");
DataModule1->Query1->SQL->Add("where IDNmb = :num");
DataModule1->Query1->ParamByName("num")->AsString = ID;
if(!DataModule1->Query1->Prepared)
DataModule1->Query1->Prepare;
DataModule1->Open();

HTH, Don




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (Desktop) 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.