Home > database >  Delphi Syntax error in FROM clause, but no from clause
Delphi Syntax error in FROM clause, but no from clause

Time:11-09

I'm really new to Delphi and have not yet worked with SQL (I'm a complete beginner).

I use code to connect my database and tables to my program, but as soon as I run my program, I get a Syntax error in FROM clause message.

When I select break, it highlights end; of a part of the code.

function TADOCommand.Execute(var RecordsAffected: Integer;
  const Parameters: OleVariant): _Recordset;
var
  VarRecsAffected: OleVariant;
begin
  SetConnectionFlag(cfExecute, True);
  try
    Initialize;
    Result := CommandObject.Execute(VarRecsAffected, Parameters,
              Integer(CommandObject.CommandType)   ExecuteOptionsToOrd
              (FExecuteOptions));
    RecordsAffected := VarRecsAffected;
  finally
    SetConnectionFlag(cfExecute, False);
  end;
end;

I have three tables, of which two display on their grids, but one is not displaying on the grid, and also gives me the Syntax error in FROM clause when I want to do anything with it.

This is the code that I used to connect my database in the datamodule:

unit dmChamps_u;

interface

uses
  System.SysUtils, System.Classes, ADODB, DB; // add Ado and DB

type
  TdmChamps = class(TDataModule)
    procedure DataModuleCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    conArchers: TADOConnection;
    tblArchers: TADOTable;
    tblJT: TADOTable;
    tblMatches: TADOTable;
    dscArchers: TDataSource;
    dscMatches: TDataSource;
    dscJT: TDataSource;
  end;

var
  dmChamps: TdmChamps;

implementation

{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}

procedure TdmChamps.DataModuleCreate(Sender: TObject);
begin
  // create objects
  conArchers := TADOConnection.Create(dmChamps);
  tblArchers := TADOTable.Create(dmChamps);
  tblMatches := TADOTable.Create(dmChamps);
  tblJT := TADOTable.Create(dmChamps);
  dscArchers := TDataSource.Create(dmChamps);
  dscMatches := TDataSource.Create(dmChamps);
  dscJT := TDataSource.Create(dmChamps);

  // setup connection
  conArchers.ConnectionString :=
    'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ArchChampsDB.mdb;Mode=ReadWrite;Persist Security Info=False';
  conArchers.LoginPrompt := false;
  conArchers.Open;

  // setup table archers
  tblArchers.Connection := conArchers;
  tblArchers.TableName := 'Archers';
  // setup data source
  dscArchers.DataSet := tblArchers;
  tblArchers.Open;

  // setup table matches
  tblMatches.Connection := conArchers;
  tblMatches.TableName := 'Matches';
  // setup data source
  dscMatches.DataSet := tblMatches;
  tblMatches.Open;

  // setup table JT
  tblJT.Connection := conArchers;
  tblJT.TableName := 'Judges/Timekeepers';
  // setup data source
  dscJT.DataSet := tblJT;
  tblJT.Open;

end;

end.

I've looked through all of the questions on the From clause error already on the site, but none of the scenarios quite match my problem. I also went to Embarcadero's site and read about TableDirect, which I thought might be a possible solution, but it was already in the code.

CodePudding user response:

Your error is here

 tblJT.TableName := 'Judges/Judges';

You can't has a table with that name, or Judges or Timekeepers

You can solve do it:

 // setup table J
  tblJT.Connection := conArchers;
  tblJT.TableName := 'Judges';
  // setup data source
  dscJT.DataSet := tblJT;
  tblJT.Open;

Separated

// setup table T
  tblJT.Connection := conArchers;
  tblJT.TableName := 'Timekeepers';
  // setup data source
  dscJT.DataSet := tblJT;
  tblJT.Open;

CodePudding user response:

Maybe it is because of the slash in 'Judges/Timekeepers'.

Did you try to debug step by step going to the code in DataModuleCreate?

  • Related