| View previous topic :: View next topic |
| Author |
Message |
Tom Guest
|
Posted: Fri Oct 08, 2004 9:19 pm Post subject: Param subs for searchs |
|
|
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
|
Posted: Fri Oct 08, 2004 11:45 pm Post subject: Re: Param subs for searchs |
|
|
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
|
Posted: Sat Oct 09, 2004 1:28 pm Post subject: Re: Param subs for searchs |
|
|
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
|
Posted: Sat Oct 09, 2004 2:06 pm Post subject: Re: Param subs for searchs |
|
|
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
|
Posted: Sat Oct 09, 2004 3:37 pm Post subject: Re: Param subs for searchs |
|
|
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 |
|
 |
|