Einzelnen Beitrag anzeigen

AlexII

Registriert seit: 28. Apr 2008
1.717 Beiträge
 
FreePascal / Lazarus
 
#17

AW: Joblist - Aufgabenplaner

  Alt 30. Sep 2014, 13:11
Ich nutze hier mehrere Querys (SQLQuery1 und SQLQueryCategory), wäre es auch nur mit einem gegangen?

Delphi-Quellcode:
    // -------------------------- Category ---------------------------------------
    // Kategorie leer
    if CategoryComboBox.Text = 'then
    begin
      Form1.SQLQuery1.ParamByName('fk_category_id').Clear;
    end else if (CategoryComboBox.Items.IndexOf(CategoryComboBox.Text) = -1) and (CategoryComboBox.Text <> '') then
    begin
      // Kategorie nicht vorhanden, also neue Kategorie in die DB schreiben
      Form1.SQLQueryCategory.Close;
      Form1.SQLQueryCategory.SQL.Text := 'INSERT INTO tbcategory VALUES(NULL, :category)';
      Form1.SQLQueryCategory.ParamByName('category').AsString := CategoryComboBox.Text;
      Form1.SQLQueryCategory.ExecSQL;
      Form1.SQLTransaction1.Commit;

      // Die letzte ID auslesen
      Form1.SQLQueryCategory.Close;
      Form1.SQLQueryCategory.SQL.Text := 'SELECT last_insert_rowid() as id_tbcategory FROM tbcategory';
      Form1.SQLQueryCategory.Open;
      CategoryLastID := Form1.SQLQueryCategory.FieldByName('id_tbcategory').AsInteger;
      Form1.SQLQuery1.ParamByName('fk_category_id').AsInteger := CategoryLastID;
    end else if CategoryComboBox.Items.IndexOf(CategoryComboBox.Text) >= 0 then
    begin
      // String in der CB vorhanden, ID zuweisen
      Form1.SQLQuery1.ParamByName('fk_category_id').AsInteger := Integer(CategoryComboBox.Items.Objects[CategoryComboBox.Items.IndexOf(CategoryComboBox.Text)]);
    end;
    // -------------------------- Ende Category ----------------------------------

    Form1.SQLQuery1.ExecSQL;
    Form1.SQLTransaction1.Commit;
Bin Hobbyprogrammierer! Meine Fragen beziehen sich meistens auf Lazarus!
  Mit Zitat antworten Zitat