<%@ Page Language="Delphi" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="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>
<html>
<head>
</head>
<body style="FONT-FAMILY: arial">
<h2>Simple Data Report
</h2>
<hr size="1" />
<form runat="server">
<asp:datagrid id="DataGrid1" runat="server" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" EnableViewState="False">
<HeaderStyle font-bold="True" forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
<ItemStyle backcolor="#DEDFDE"></ItemStyle>
</asp:datagrid>
<asp:Button id="Button1" style="Z-INDEX: 100; LEFT: 284px; POSITION:
absolute; TOP: 151px" onclick="Button1Click" runat="server" Text="Bind
To Data Grid"></asp:Button>
<asp:
Label id="Label1" style="Z-INDEX: 100; LEFT: 467px; POSITION:
absolute; TOP: 156px" runat="server" Width="42px">
Label</asp:
Label>
<asp:Button id="Button2" style="Z-INDEX: 101; LEFT: 283px; POSITION:
absolute; TOP: 182px" onclick="Button2Click" runat="server" Text="Button"></asp:Button>
</form>
</body>
</html>
(*
请设置你的webconfig文件如下:
*)
<configuration>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="DelphiProvider" />
</assemblies>
<compilers>
<compiler language="Delphi" extension=".pas"
type="Borland.Delphi.DelphiCodeProvider,DelphiProvider" />
</compilers>
</compilation>
</system.web>
</configuration>
<configuration>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="DelphiProvider" />
</assemblies>
<compilers>
<compiler language="Delphi" extension=".pas"
type="Borland.Delphi.DelphiCodeProvider,DelphiProvider" />
</compilers>
</compilation>
</system.web>
</configuration>
本文地址:http://com.8s8s.com/it/it4695.htm