Einzelnen Beitrag anzeigen

Benutzerbild von Mavarik
Mavarik

Registriert seit: 9. Feb 2006
Ort: Stolberg (Rhld)
4.130 Beiträge
 
Delphi 10.3 Rio
 
#1

ASP.NET und MySQL.NET auslesen eine Shopliste, einfacher?

  Alt 15. Sep 2006, 11:32
Hallo Zusammen!

Ich versuche mich krampfhaft in MySQL einzuarbeiten. Es soll folgende Liste erzeugt werden:

AUTOS (10)
LKWs (3)
Motorräder (3)


in der ASPX Datei steh:
Delphi-Quellcode:
 

<%#CatList()%></p>
Und mein QuellCode sieht so aus:
Delphi-Quellcode:
function TWebForm1.CatList:string;
Var
  Connection1,
  Connection2 : IDBConnection;
  command1,
  command2 : IDbCommand;
  reader1,
  reader2 : IDataReader;
  S : String;
begin
  Connection1 := MySQLConnection.Create('server=localhost;uid=ich;pwd=wasauch;database=fahrzeuge');
  Connection2 := MySQLConnection.Create('server=localhost;uid=ich;pwd=wasauch;database=fahrzeuge');
   try
     Connection1.Open;
     Connection2.Open;
     command1 := connection1.CreateCommand();
     command2 := connection2.CreateCommand();
    try
     command1.CommandText := 'Select * from CatLookup where ID>1'; // 1=keine Auswahl

     reader1 := command1.ExecuteReader();
      try
        result := '';
        while reader1.Read() do
          begin
            S := reader1.GetString(1)+ ' (';
            command2.CommandText := 'Select COUNT(*) from Shop where Categorie='+reader1.GetString(0);
            reader2 := command2.ExecuteReader();
            try
            if reader2.Read then
              begin
                S := S + reader2.GetString(0)+')
';
                if reader2.GetInt32(0) > 0 then // Nur wenn Anzahl > 0 auch den Menuepunkt zeigen...
                  Result := result + S;
              end;
            finally
              reader2.Dispose();
            end;
          end;

      finally
        reader1.Dispose();
      end;

    finally
      command1.Dispose();
      command2.Dispose();
    end;

  finally
    Connection1.Close;
    Connection2.Close;
    connection1.Dispose();
    connection2.Dispose();
   end;
end;
Boh ist das aufwending. Geht das nicht einfacher? Werden bei MySQL wirklich 2 Connections benötigt?

Grüsse Frank
  Mit Zitat antworten Zitat