Einzelnen Beitrag anzeigen

fly_singapore

Registriert seit: 31. Mär 2007
Ort: Kolbnitz/Bonn Österreich/Deutschland
96 Beiträge
 
Delphi 2006 Enterprise
 
#3

Re: DatabankObjekte von anderen ASPX-Seiten zugreifen

  Alt 14. Aug 2007, 08:18
Zunächst einmal habe ich eine ASPX-Seite erstellt mit dem typischen HelloWorld -Beispiel, was aber jetzt nicht Gegenstand der Diskussion ist. Dann habe ich ein DBWEBTextbox in den Designer geschoben.

Delphi-Quellcode:

unit WebForm_test;

interface

uses
  System.Collections, System.ComponentModel,
  System.Data, System.Drawing, System.Web, System.Web.SessionState,
  System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls,
  Borland.Data.Provider, Borland.Data.Web, db_modul;

type
  TWebForm_Test = class(System.Web.UI.Page)
  {$REGION 'Vom Designer verwalteter Code'}
  strict private
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict private
    procedure Page_Load(sender: System.Object; e: System.EventArgs);
  strict protected
    Button1: System.Web.UI.WebControls.Button;
    BdpConnection1: Borland.Data.Provider.BdpConnection;
    DBWebTextBox1: Borland.Data.Web.DBWebTextBox;
    procedure OnInit(e: EventArgs); override;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

implementation

{$REGION 'Vom Designer verwalteter Code'}
/// <summary>
/// Erforderliche Methode zur Unterstützung des Designers --
/// ändern Sie die Methode nicht mit dem Quelltext-Editor
/// </summary>
procedure TWebForm_Test.InitializeComponent;
begin
  Self.BdpConnection1 := Borland.Data.Provider.BdpConnection.Create;
  Include(Self.Button1.Click, Self.Button1_Click);
  //
  // BdpConnection1
  //
  Self.BdpConnection1.ConnectionOptions := '';
  Include(Self.Load, Self.Page_Load);
end;
{$ENDREGION}

procedure TWebForm_Test.Page_Load(sender: System.Object; e: System.EventArgs);





begin


end;

procedure TWebForm_Test.OnInit(e: EventArgs);
begin
  //
  // Erforderlich zur Unterstützung des Designers
  //
  InitializeComponent;
  inherited OnInit(e);
end;

procedure TWebForm_Test.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
  button1.Text := button1.Text + 'Hallo Entwickler';
end;

end.
Dann habe ich eine weitere ASPX-Datei samt dahinterliegender Unit gebaut, welches die Controls BdpConnection, BdpCommand, BdpDataAdapter, Dataset und als Kontrolle ein DBWebDataSource und DBWebGrid beinhaltet.

Delphi-Quellcode:

unit DB_modul;

interface

uses
  System.Collections, System.ComponentModel,
  System.Data, System.Drawing, System.Web, System.Web.SessionState,
  System.Web.UI, System.Web.UI.WebControls, System.Web.UI.HtmlControls,
  Borland.Data.Common, Borland.Data.Provider, System.Globalization,
  Borland.Data.Web, System.Data.Common;

type
  TWebForm1 = class(System.Web.UI.Page)
  {$REGION 'Vom Designer verwalteter Code'}
  strict private
    procedure InitializeComponent;
  {$ENDREGION}
  strict private
    procedure Page_Load(sender: System.Object; e: System.EventArgs);
  strict protected
    Bdp_Connect_Migration: Borland.Data.Provider.BdpConnection;
    bdpSelectCommand1: Borland.Data.Provider.BdpCommand;
    bdpInsertCommand1: Borland.Data.Provider.BdpCommand;
    bdpUpdateCommand1: Borland.Data.Provider.BdpCommand;
    bdpDeleteCommand1: Borland.Data.Provider.BdpCommand;
    BdpDataAdapter1: Borland.Data.Provider.BdpDataAdapter;
    dataSet_Migration: System.Data.DataSet;
    DBWebDataSource_Migration: Borland.Data.Web.DBWebDataSource;
    DataTable1: System.Data.DataTable;
    DataColumn1: System.Data.DataColumn;
    DataColumn2: System.Data.DataColumn;
    DBWebGrid1: Borland.Data.Web.DBWebGrid;
    procedure OnInit(e: EventArgs); override;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

implementation

{$REGION 'Vom Designer verwalteter Code'}
/// <summary>
/// Erforderliche Methode zur Unterstützung des Designers --
/// ändern Sie die Methode nicht mit dem Quelltext-Editor
/// </summary>
procedure TWebForm1.InitializeComponent;
type
  TArrayOfSystem_Data_Common_DataTableMapping = array of System.Data.Common.DataTableMapping;
  TArrayOfSystem_Data_Common_DataColumnMapping = array of System.Data.Common.DataColumnMapping;
  TArrayOfSystem_Data_DataTable = array of System.Data.DataTable;
  TArrayOfSystem_Data_DataColumn = array of System.Data.DataColumn;
begin
  Self.Bdp_Connect_Migration := Borland.Data.Provider.BdpConnection.Create;
  Self.bdpSelectCommand1 := Borland.Data.Provider.BdpCommand.Create;
  Self.bdpInsertCommand1 := Borland.Data.Provider.BdpCommand.Create;
  Self.bdpUpdateCommand1 := Borland.Data.Provider.BdpCommand.Create;
  Self.bdpDeleteCommand1 := Borland.Data.Provider.BdpCommand.Create;
  Self.BdpDataAdapter1 := Borland.Data.Provider.BdpDataAdapter.Create;
  Self.dataSet_Migration := System.Data.DataSet.Create;
  Self.DBWebDataSource_Migration := Borland.Data.Web.DBWebDataSource.Create;
  Self.DataTable1 := System.Data.DataTable.Create;
  Self.DataColumn1 := System.Data.DataColumn.Create;
  Self.DataColumn2 := System.Data.DataColumn.Create;
  (System.ComponentModel.ISupportInitialize(Self.BdpDataAdapter1)).BeginInit;
  (System.ComponentModel.ISupportInitialize(Self.dataSet_Migration)).BeginInit;
  (System.ComponentModel.ISupportInitialize(Self.DBWebDataSource_Migration)).BeginInit;
  (System.ComponentModel.ISupportInitialize(Self.DataTable1)).BeginInit;
  //
  // Bdp_Connect_Migration
  //
  Self.Bdp_Connect_Migration.ConnectionOptions := 'transaction isolation=Rea' +
  'dCommitted;blobsize=1024';
  Self.Bdp_Connect_Migration.ConnectionString := 'assembly=Borland.Data.Mssq' +
  'l,Version=2.5.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;vendorc' +
  'lient=sqloledb.dll;pooling=True;grow on demand=True;database=Migration;us' +
  'ername=tiger;max pool size=100;password=scott;provider=MSSQL;min pool siz' +
  'e=0;hostname=164.24.61.158';
  //
  // bdpSelectCommand1
  //
  Self.bdpSelectCommand1.CommandOptions := nil;
  Self.bdpSelectCommand1.CommandText := 'SELECT S_GPNR, S_QKDNR FROM dbo.tbl' +
  '_mig';
  Self.bdpSelectCommand1.CommandType := System.Data.CommandType.Text;
  Self.bdpSelectCommand1.Connection := Self.Bdp_Connect_Migration;
  Self.bdpSelectCommand1.ParameterCount := (SmallInt(0));
  Self.bdpSelectCommand1.SchemaName := nil;
  Self.bdpSelectCommand1.Transaction := nil;
  Self.bdpSelectCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None;
  //
  // bdpInsertCommand1
  //
  Self.bdpInsertCommand1.CommandOptions := nil;
  Self.bdpInsertCommand1.CommandText := 'INSERT INTO dbo.tbl_mig (S_QKDNR ) ' +
  'VALUES ( ?)';
  Self.bdpInsertCommand1.CommandType := System.Data.CommandType.Text;
  Self.bdpInsertCommand1.Connection := Self.Bdp_Connect_Migration;
  Self.bdpInsertCommand1.ParameterCount := (SmallInt(1));
  Self.bdpInsertCommand1.Parameters.Add(Borland.Data.Common.BdpParameter.Create('S' +
      '_QKDNR', Borland.Data.Common.BdpType.Double, Borland.Data.Common.BdpType.Unknown,
        8, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
        0, 'S_QKDNR', System.Data.DataRowVersion.Current, nil));
  Self.bdpInsertCommand1.SchemaName := nil;
  Self.bdpInsertCommand1.Transaction := nil;
  Self.bdpInsertCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None;
  //
  // bdpUpdateCommand1
  //
  Self.bdpUpdateCommand1.CommandOptions := nil;
  Self.bdpUpdateCommand1.CommandText := 'UPDATE dbo.tbl_mig SET S_QKDNR = ? ' +
  'WHERE ID = ? AND S_QKDNR = ?';
  Self.bdpUpdateCommand1.CommandType := System.Data.CommandType.Text;
  Self.bdpUpdateCommand1.Connection := Self.Bdp_Connect_Migration;
  Self.bdpUpdateCommand1.ParameterCount := (SmallInt(3));
  Self.bdpUpdateCommand1.Parameters.Add(Borland.Data.Common.BdpParameter.Create('S' +
      '_QKDNR', Borland.Data.Common.BdpType.Double, Borland.Data.Common.BdpType.Unknown,
        8, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
        0, 'S_QKDNR', System.Data.DataRowVersion.Current, nil));
  Self.bdpUpdateCommand1.Parameters.Add(Borland.Data.Common.BdpParameter.Create('I' +
      'DOriginal', Borland.Data.Common.BdpType.Double, Borland.Data.Common.BdpType.Unknown,
        8, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
        0, 'ID', System.Data.DataRowVersion.Original, nil));
  Self.bdpUpdateCommand1.Parameters.Add(Borland.Data.Common.BdpParameter.Create('S' +
      '_QKDNROriginal', Borland.Data.Common.BdpType.Double, Borland.Data.Common.BdpType.Unknown,
        8, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
        0, 'S_QKDNR', System.Data.DataRowVersion.Original, nil));
  Self.bdpUpdateCommand1.SchemaName := nil;
  Self.bdpUpdateCommand1.Transaction := nil;
  Self.bdpUpdateCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None;
  //
  // bdpDeleteCommand1
  //
  Self.bdpDeleteCommand1.CommandOptions := nil;
  Self.bdpDeleteCommand1.CommandText := 'DELETE FROM dbo.tbl_mig WHERE ID = ' +
  '? AND S_QKDNR = ?';
  Self.bdpDeleteCommand1.CommandType := System.Data.CommandType.Text;
  Self.bdpDeleteCommand1.Connection := Self.Bdp_Connect_Migration;
  Self.bdpDeleteCommand1.ParameterCount := (SmallInt(2));
  Self.bdpDeleteCommand1.Parameters.Add(Borland.Data.Common.BdpParameter.Create('I' +
      'DOriginal', Borland.Data.Common.BdpType.Double, Borland.Data.Common.BdpType.Unknown,
        8, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
        0, 'ID', System.Data.DataRowVersion.Original, nil));
  Self.bdpDeleteCommand1.Parameters.Add(Borland.Data.Common.BdpParameter.Create('S' +
      '_QKDNROriginal', Borland.Data.Common.BdpType.Double, Borland.Data.Common.BdpType.Unknown,
        8, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
        0, 'S_QKDNR', System.Data.DataRowVersion.Original, nil));
  Self.bdpDeleteCommand1.SchemaName := nil;
  Self.bdpDeleteCommand1.Transaction := nil;
  Self.bdpDeleteCommand1.UpdatedRowSource := System.Data.UpdateRowSource.None;
  //
  // BdpDataAdapter1
  //
  Self.BdpDataAdapter1.Active := True;
  Self.BdpDataAdapter1.DataSet := Self.dataSet_Migration;
  Self.BdpDataAdapter1.DataTable := Self.DataTable1;
  Self.BdpDataAdapter1.DeleteCommand := Self.bdpDeleteCommand1;
  Self.BdpDataAdapter1.InsertCommand := Self.bdpInsertCommand1;
  Self.BdpDataAdapter1.SelectCommand := Self.bdpSelectCommand1;
  Self.BdpDataAdapter1.StartRecord := 0;
  Self.BdpDataAdapter1.TableMappings.AddRange(TArrayOfSystem_Data_Common_DataTableMapping.Create(System.Data.Common.DataTableMapping.Create('T' +
          'able', 'tbl_mig', TArrayOfSystem_Data_Common_DataColumnMapping.Create(System.Data.Common.DataColumnMapping.Create('I' +
                'D', 'ID'), System.Data.Common.DataColumnMapping.Create('S_Q' +
                'KDNR', 'S_QKDNR')))));
  Self.BdpDataAdapter1.UpdateCommand := Self.bdpUpdateCommand1;
  //
  // dataSet_Migration
  //
  Self.dataSet_Migration.DataSetName := 'NewDataSet';
  Self.dataSet_Migration.Locale := System.Globalization.CultureInfo.Create('d' +
    'e-DE');
  Self.dataSet_Migration.Tables.AddRange(TArrayOfSystem_Data_DataTable.Create(Self.DataTable1));
  //
  // DBWebDataSource_Migration
  //
  Self.DBWebDataSource_Migration.DataSource := Self.dataSet_Migration;
  Self.DBWebDataSource_Migration.ErrorDlgBackColor := System.Drawing.Color.Azure;
  Self.DBWebDataSource_Migration.ErrorDlgBorderColor := System.Drawing.Color.Red;
  Self.DBWebDataSource_Migration.ErrorDlgForeColor := System.Drawing.Color.Black;
  //
  // DataTable1
  //
  Self.DataTable1.Columns.AddRange(TArrayOfSystem_Data_DataColumn.Create(Self.DataColumn1,
          Self.DataColumn2));
  Self.DataTable1.TableName := 'tbl_mig';
  //
  // DataColumn1
  //
  Self.DataColumn1.ColumnName := 'S_GPNR';
  Self.DataColumn1.DataType := TypeOf(System.Double);
  //
  // DataColumn2
  //
  Self.DataColumn2.ColumnName := 'S_QKDNR';
  Self.DataColumn2.DataType := TypeOf(System.Double);
  Include(Self.Load, Self.Page_Load);
  (System.ComponentModel.ISupportInitialize(Self.BdpDataAdapter1)).EndInit;
  (System.ComponentModel.ISupportInitialize(Self.dataSet_Migration)).EndInit;
  (System.ComponentModel.ISupportInitialize(Self.DBWebDataSource_Migration)).EndInit;
  (System.ComponentModel.ISupportInitialize(Self.DataTable1)).EndInit;
end;
{$ENDREGION}

procedure TWebForm1.Page_Load(sender: System.Object; e: System.EventArgs);
begin
  // TODO: Hier Anwendercode zum Initialisieren der Seite einfügen
end;

procedure TWebForm1.OnInit(e: EventArgs);
begin
  //
  // Erforderlich zur Unterstützung des Designers
  //
  InitializeComponent;
  inherited OnInit(e);
end;

end.
Dieses Unit habe ich in meiner delphi-Logik in der WebForm_Test.ASPX im Bereich USES mit eingebunden
Naja.. vielleicht war das zu blauäugig !!!!!
Peter Steffens
  Mit Zitat antworten Zitat