Results 1 to 6 of 6

Thread: dropdownlist dynamisch opvullen met waarden uit tabel

  1. #1

    dropdownlist dynamisch opvullen met waarden uit tabel

    ik weet het het klinkt super simpel maar het lukt mij niet om een dropdownlist op te vullen met waarden uit een tabel. Ik maak gebruik van delphi 8, dus .net en een firebird sql connectie.

    ter illustratie :

    Code:
    procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
    var
      conn : FirebirdSql.Data.Firebird.FbConnection;
      command : FirebirdSql.Data.Firebird.FbCommand;
      trans : FirebirdSql.Data.Firebird.FbTransaction;
      tmp: ListItem;
      sql : string;
    
    begin
      conn := FirebirdSql.Data.Firebird.FbConnection.Create();
      conn.ConnectionString := 'User=xxxxx;Password=xxxxxx;Database=C:\databases\vivaldi.gdb;DataSource=exdevelop;Port=3050;Dialect=3;Charset=NONE;Role=;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;Packet Size=8192;ServerType=0';
      try
        conn.Open();
      except
        Response.Redirect('fout.aspx?fout=Er kan geen connectie gemaakt worden met de database.');
      end;
    
      trans := conn.BeginTransaction();
      sql := 'select * from Rubrieken';
      command := FbCommand(sql,conn,trans);
    Ik krijg al een foutmelding bij het gebruik van de fbCommand functie.
    Ik weet niet zeker of dit de correcte manier is om het zo te doen, ben een newbie in zowel delphi als .net
    Mijn dropdownlist heet "lstRubrieken" en eens de select statement correct verlopen is dan wil ik de records overlopen en de waarden in een string tmp stoppen en zo lstRubrieken.Items.Add(tmp) doen.

    Anyway als iemand een oplossing weet, of een betere manier weet that would be great.

    thx

  2. #2
    Wat voor foutmelding krijg je? Wordt je connectie wel goed geopend?
    Marcel

  3. #3
    SillyMember
    Join Date
    May 2003
    Location
    Gent
    Posts
    7,725
    Bijvoorbeeld (met DataReader)
    Code:
    procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
    begin
       if IsPostBack then Exit;
      DataBind;
    end;
    
    procedure TWebForm1.DropDownList1_DataBinding(
           sender: System.Object; e: System.EventArgs);
    var
      Command : FbCommand;
      Connection: FbConnection;
      Reader: FbDataReader;
    begin
      Connection := FbConnection.Create(ConnectionString);
      Command := FbCommand.Create('select FULL_NAME from Employee', Connection);
      Connection.Open;
      Reader :=  Command.ExecuteReader(CommandBehavior.CloseConnection);
      while Reader.Read do
        DropDownList1.Items.Add(Reader.GetValue(0).ToString);
      // sluit ook connectie, vanwege CommandBehavior.CloseConnection
      Reader.Close;
    end;
    All methodologies are based on fear. -- Kent Beck.

  4. #4
    SillyMember
    Join Date
    May 2003
    Location
    Gent
    Posts
    7,725
    Of met een DataTable:
    Code:
    procedure TWebForm1.DropDownList2_DataBinding(
         sender: System.Object; e: System.EventArgs);
    var
      Adapter: FbDataAdapter;
      Table: DataTable;
    begin
      Adapter := FbDataAdapter.Create('select FULL_NAME from Employee',
                    FbConnection.Create(ConnectionString));
      Table := DataTable.Create('Employee');
      Adapter.Fill(Table);
      DropDownList2.DataSource := Table ;
      DropDownList2.DataTextField := 'FULL_NAME'
    end;
    All methodologies are based on fear. -- Kent Beck.

  5. #5
    thx problem solved

  6. #6
    • Verplaatst van Databases naar .NET
    Marcel

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 10-Aug-04, 23:11
  2. een veld lezen uit een tabel
    By FreakyOne in forum Algemeen
    Replies: 11
    Last Post: 20-Oct-02, 23:38
  3. Replies: 1
    Last Post: 15-Feb-02, 00:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •