Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Базы данных > Поиск по базе


Автор: Flenger 21.1.2007, 17:10
Не получается сделать поиск записей методом FinedNearest

Вот мой код

Код


void __fastcall TForm1::Button1Click(TObject *Sender)
{
Table1->IndexFieldNames = "Last Name;Name";  \\ индексирую таблицу по полям
Table1->FindNearest(OPENARRAY(TVarRec,(Edit1->Text,Edit2->Text))); 
}



Компиляция проходит успешно а потом выдаёт сообщение(При нажатии на кнопку):

Table1: No index for fields ‘Last Name;Name’
    
Это типа я моя таблица не содержит индексов с именами Last Name;Name????

Помогите что зделать? smile 

Автор: Rodman 21.1.2007, 20:20
а тебе обязательно ее индексировать???

вот в хелпе нашел
Код

//The following example performs an incremental search on a table.  The form contains a db grid, an edit box, a data source, and a client dataset. As //the user types in the edit box, the cursor of the grid moves to the nearest match in the dataset.

void __fastcall TForm1::FormCreate(TObject *Sender)

{
  ClientDataSet1->FileName = "Customer.xml";
  ClientDataSet1->Active = true;
  ClientDataSet1->IndexName = "ByCompany";
}

void __fastcall TForm1::Edit1Change(TObject *Sender)

{
ClientDataSet1->FindNearest(ARRAYOFCONST((Edit1->Text)));
}


и 
Код

//The following example performs an incremental search on a table.  The form contains a db grid, an edit box, a data source, and a table. As the user //types in the edit box, the cursor of the grid moves to the nearest match in the table.

void __fastcall TForm1::FormCreate(TObject *Sender)

{
  Table1->DatabaseName = "DBDemos";
  Table1->TableName = "Customer.db";
  Table1->Active = true;
  Table1->IndexName = "ByCompany";
}

void __fastcall TForm1::Edit1Change(TObject *Sender)

{
  Table1->FindNearest(ARRAYOFCONST((Edit1->Text)));
}

Автор: Anikmar 21.1.2007, 21:10
FindNearest работает по текущему ключу, по крайней мере с PARADOX.

Если идет поиск по полю, которое индексировано, но ключ не текущий - не работало ( у меня). Насколько помню, я переставлял текущий индекс.

Автор: Flenger 21.1.2007, 22:01
Anikmar :"Насколько помню, я переставлял текущий индекс."

А как это делать smile  я просто новичёк

 


Автор: Anikmar 22.1.2007, 09:32
Порылся, нашел такой код:
Код

bool FindUniKey(TTable *Table, int Key, AnsiString Field)
{
    AnsiString CurrentIndex;
    bool Ret;

    CurrentIndex = Table -> IndexName;
    Table -> IndexFieldNames = Field;
    Ret = Table -> FindKey(ARRAYOFCONST((Key)));
    Table -> IndexName = CurrentIndex;
    return Ret;
}



Автор: Flenger 24.1.2007, 21:08
Всё работает нормально через метод Locate

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TLocateOptions SearchOptions;

Table1->Locate("Robota",Edit1->Text,SearchOptions<<loPartialKey<<loCaseInsensitive);
}

Спасибо за помощь Anikmar, Rodman!!!!

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)