Hello!
I have a question about how to search a simple database. I have a Table ,a DataSource ,a DBGrid ,a button(for search) and an EditBox. I connected everything with my previously created Paradox7 database and everything shows nicely on the DBGrid. My question is , how can i search the database with the word or vale entered trough the edit box?
I tried this but it`s not working. I got it to work but with only one field input " Table1->Locate("Customer")... " , when i enter more fields to search in it`s not working...
void __fastcall TForm3::Button1Click(TObject *Sender)
{
TLocateOptions Opts;
Opts.Clear();
Opts << loCaseInsensitive;
Variant input[4];
input[0]=Edit1->Text;
input[1]=Edit1->Text;
input[2]=Edit1->Text;
input[3]=Edit1->Text;
bool control = Table1->Locate("Customer;ID;Phone",VarArrayOf(input,4) ,Opts);
if(control==0) ShowMessage("The search has failed!");
}
//---------------------------------------------------------------------------
Comments
[CODE]
void __fastcall TForm6::FormShow(TObject *Sender)
{
int i = 1;
int p = 0;
int money =0;
Edit3->Text = Form1->ExistingVehicleList->Text; //This is what iam searching what ever is in that textbox
Table1->First(); //starts at top of DAtabase
do
{ if(Table1->Fields->Fields[4]->AsString == Edit3->Text)//if the text(searched item) = the item in field 4 which is my list of items name
{
StringGrid1->Rows[0]->CommaText = "ProPM Item_Repaired Descreption Cost Date";
StringGrid1->RowCount = i +1;
//All this stuff inputs the info into the cells on the table from the database as long as field 4 is equeal to my search text
StringGrid1->Cells[1][i] = Table1->Fields->Fields[0]->AsString;
StringGrid1->Cells[2][i] = Table1->Fields->Fields[1]->AsString;
StringGrid1->Cells[3][i] = Table1->Fields->Fields[2]->AsInteger;
StringGrid1->Cells[4][i] = Table1->Fields->Fields[3]->AsString;
i=i+1;
money = money + Table1->Fields->Fields[2]->AsInteger;
p = 1;
}
Table1->Next(); //goes to the next database field
} while(Table1->Eof == false) ; //searches database till it the end of hte database
if(p == 0)
StringGrid1->RowCount = 0;
Edit1->Text = StringGrid1->RowCount - 1;
Edit2->Text = money;
DBNavigator->BtnClick(nbInsert);
}
[/CODE]