Search code examples
delphidelphi-7

Searching for a title in a .MDB


Just another task for IT. The question is:

btnSearch: The user must be able to search for a book by entering the books title. Use an input box to get the title from the user. Display the title and the ISBN number

I have the Database with multiple tables, with multiple columns in each. The book title is in the tblBooks table.

Here's my Delphi code at the moment:

procedure TfrmLibrary.btnSearchClick(Sender: TObject);
var
  sBookName : String;
begin
  sBookName := InputBox('Enter book Name','','') ;
  qryLibrary.Active := False;
  qryLibrary.SQL.Text := 'SELECT * FROM tblBooks WHERE TITLE = ' + sBookName + ' ;';
  qryLibrary.Active := True;

Its giving me an error saying:

Project question1 raised exception class EOLeException with message 'Parameter Karoonag has no default value' Process stopped

Oh, 'Karoonag' is the title of a book. Please give me a hand here D:


Solution

  • Okay, I found what I was doing wrong.

    Where I do the sql text, I was missing the quotation marks for the book. Heres my code now:

    procedure TfrmLibrary.btnSearchClick(Sender: TObject);
    var
      sBookName : String;
    begin
      sBookName := InputBox('Enter book Name','','') ;
      qryLibrary.Active := False;
      qryLibrary.SQL.Text := 'SELECT * FROM tblBooks WHERE TITLE = "' + sBookName + '" ;'; //<--- ""
      qryLibrary.Active := True;