I have 2 tables: 1. Projects, 2. Article_Weights. Table Projects is connected to first DBLookUpCombobox DBLkpCbo_Projects. It has one column Project which contains four digit numbers. (1001, 1004, 1008,...)
Table Article_Weights containing columns Project, Article_Number, Article_Weights etc. This table is connected with DBLookUpCombobox DBLkpCbo_Articles.
What I want to achieve is when I choose from first combobox some project, second combobox will show just article numbers which belongs to that projects. After that when I choose some article number from second combobox, information about this article will be shown in DBGrid.
Filtering is working. I am stuck on last point. When I choose some article number I get error "Data types do not match in the expression criteria"
This is my code:
procedure TMainForm.DBLkpCbo_ProjectSelect(Sender: TObject);
begin
if DBLkpCbo_Project.ItemIndex <> -1 then begin
SQLQuery2.Active:=true;
//SQLQuery1.ApplyUpdates();
SQLTransaction1.Commit();
SQLQuery2.Close;
SQLQuery2.SQL.Text:='SELECT Article_Number FROM Article_Weights WHERE Project = '+DBLkpCbo_Project.Text+'';
SQLQuery2.Open;
end;
end;
procedure TMainForm.DBLkpCbo_ArticleChange(Sender: TObject);
begin
if DBLkpCbo_Article.ItemIndex <> -1 then begin
//DBGrid1.Enabled:=true;
SQLQuery3.Active:=true;
//SQLQuery1.ApplyUpdates();
SQLTransaction1.Commit();
SQLQuery3.Close;
SQLQuery3.SQL.Text:='SELECT Article_Number FROM Article_Weights WHERE Article_Number='+DBLkpCbo_Article.Text+'';
SQLQuery3.Open;
end;
end;
Thank you for any answer
Is Article_Number a text field or (as the name suggests) a numeric field? If it is a number is DBLkpCbo_Article.Text actually numeric (i.e. a string containing a valid number)? If, as I suspect, Article_Number is a text field, you have omitted the quotation marks:
SQLQuery3.SQL.Text:='SELECT Article_Number FROM Article_Weights WHERE Article_Number='''+DBLkpCbo_Article.Text+'''';