Mega Code Archive

 
Categories / Delphi / .NET
 

How to create and control asp.net programs with delphi events

Title: How to create and control asp.net programs with delphi events @ Page Language="Delphi" % @ import Namespace="System.Data" % @ import Namespace="System.Data.OleDb" % ="server" procedure Button1Click(Sender: System.Object; E: EventArgs); var MyConnection : OleDbConnection ; dbReader : OleDbDataReader; cmd : OleDbCommand; abc : string; outval : string; intval : longint; begin abc := 'Provider=Microsoft.Jet.OLEDB.4.0;Password=;Data Source=c:\mydb.mdb'; MyConnection := OleDbConnection.Create(abc); MyConnection.Open; cmd := MyConnection.CreateCommand; cmd.CommandText := 'Select * from Table1'; dbReader := cmd.ExecuteReader; while (dbReader.Read) do begin intval := dbReader.GetInt32(0); outval := dbReader.GetString(1); end; Label1.Text := inttostr(intval); end; procedure Button2Click(Sender: System.Object; E: EventArgs); var ConnStr : string; CommTxt : string; MyConnection : OleDbConnection ; abc : string; cmdText : string; cmd : OleDbCommand; begin ConnStr := 'Provider=Microsoft.Jet.OLEDB.4.0;Password=;Data Source=c:\mydb.mdb'; CommTxt := 'select andy as [first name], chapman as [Last Name] from Table1'; abc := 'Provider=Microsoft.Jet.OLEDB.4.0;Password=;Data Source=c:\mydb.mdb'; MyConnection := OleDbConnection.Create(abc); cmd := OleDbCommand.Create(CommTxt,MyConnection); MyConnection.Open; DataGrid1.DataSource := cmd.ExecuteReader(CommandBehavior.CloseConnection); DataGrid1.DataBind(); end; /script /head ="FONT-FAMILY: arial" Simple Data Report /h2 ="1" / ="server" :datagrid id="DataGrid1" runat="server" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" EnableViewState="False" -bold="True" forecolor="White" backcolor="#4A3C8C"/headerstyle ="#DEDFDE"/itemstyle /asp :Button id="Button1" style="Z-INDEX: 100; LEFT: 284px; POSITION: absolute; TOP: 151px" onclick="Button1Click" runat="server" Text="Bind To Data Grid"/asp :Label id="Label1" style="Z-INDEX: 100; LEFT: 467px; POSITION: absolute; TOP: 156px" runat="server" Width="42px"Label/asp :Button id="Button2" style="Z-INDEX: 101; LEFT: 283px; POSITION: absolute; TOP: 182px" onclick="Button2Click" runat="server" Text="Button"/asp /form /body /html (* To make the code execute locally you should download webmatrix which is an excellent free downloadable aspx development environment. All you need then is the following code in a web.config document : *) .web ="true" ="DelphiProvider" / /assemblies ="Delphi" extension=".pas" type="Borland.Delphi.DelphiCodeProvider,DelphiProvider" / /compilers /compilation /system /configuration (* and inside a bin directory at the root the DelphiProvider.dll. You may now create and run asp.net applications with delphi as you chosen method of codeing.