国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET/Perl.NET 數據庫訪問例子

2024-07-10 12:55:34
字體:
來源:轉載
供稿:網友
asp.net/perl.net database access example
one of the features of the .net framework is its ability to handle multiple languages. third party compiler vendors can create and implement a compiler targeted for the .net runtime. in fact, over the course of the next year, you can expect to see some 28 languages ported to the .net runtime. this will allow companies with a huge codebase in a "non-microsoft language" to continue building onto their investment.

note: all of the software required to create and run asp.net pages built using perl.net can be downloaded here.

here is the code for the whole page (we will dissect and explain each bit of the code throughout the rest of the article):

<%@ page
language="perl" %>
<script runat="server">

use namespace "system::data";
use namespace "system::data::sqlclient";

=for interface
protected override void onload(system.eventargs e);
=cut

sub onload {
my($this, $e) = @_;

my $myconnection = sqlconnection->new("data source=(local); trusted_connection=yes; initial
catalog=pubs");
my $mycommand = sqlcommand->new("select * from publishers", $myconnection);

$myconnection->open();

$this->{mydatagrid}{datasource} = $mycommand->executereader(perlnet::enum
("commandbehavior.closeconnection"));
$this->{mydatagrid}->databind;
}

</script>
<html>
<body>
<form runat="server">
<asp:datagrid id="mydatagrid" runat="server" />
</form>
</body>
</html>

we need to set the language attribute (in our declaration) equal to 'perl'. we do this so it is clear to the .net runtime exactly which compiler it must invoke. the following code accomplishes this task:

<%@ page
language="perl" %>


now, we need place all of our perl.net code inside <script runat="server"</script> blocks just as we would if we were using vb.net or c#. here is where you will notice one (there are more) difference between vb.net/c#/jscript.net and perl.net pages. in perl.net, rather than using import declarations outside of the <script> blocks the code that imports the required namespaces is placed inside the <script> blocks. this code uses the following syntax:


use
namespace "system::data";
use namespace "system::data::sqlclient";


we want code to execute each time the page is loaded so we must explicitly define our onload event in order for the page to recognize it. the following code accomplishes this task:

=for interface
protected override void onload(system.eventargs e);
=cut

note: all events in the page must be declared using code similar to that above. also, all interface declarations must be flush left on the page (ie '=for interface' must start in the left most column on the page).

next, we declare our onload event. the following code declares the onload event and places any arguments into the scalar variables $this and $e:

sub onload {
my($this, $e) = @_;


so, we have declared our onload event and now we need to write the code to be executed in the event. the code in our example connects to a sql server database and retrieves information in the form of a datareader. first, we will examine the code that connects to sql server and selects the desired information.

my $myconnection = sqlconnection->new("data
source=(local); trusted_connection=yes; initial catalog=pubs");
my $mycommand = sqlcommand->new("select * from publishers", $myconnection);

$myconnection->open();

'my' declares variables to be local to the enclosing block - in our case the onload event. in perl.net, we call an object's methods using this syntax: object->methodname.

ok, we have created the necessary objects and opened our connection to sql server. the variable $this contains a reference to the our page. anytime we want to reference controls on the page (ie mydatagrid) we use $this. so, mydatagrid is a property of the page - all properties are referenced using this syntax: {propertyname}.

$this->{mydatagrid}{datasource}
= $mycommand->executereader(perlnet::enum("commandbehavior.closeconnection"));
$this->{mydatagrid}->databind;

the code above also demonstrates how we use enumerations in perl.net. enumerations are referenced using the following syntax: perlnet::enum("name of enumeration"). the rest of the code (html and datagrid declaration) in the page is no different than in a asp.net page written in vb.net or c#.

this example is just a small taste of what we can do with perl.net! hopefully, this article will jumpstart all you perl developers into trying perl.net/asp.net!
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 武陟县| 四子王旗| 隆子县| 隆安县| 扶风县| 雅江县| 惠安县| 崇州市| 西林县| 兰坪| 义马市| 开江县| 富顺县| 荔浦县| 南木林县| 五大连池市| 潮安县| 乌拉特后旗| 宿松县| 酉阳| 武鸣县| 灌南县| 河曲县| 赣州市| 无为县| 长治市| 双城市| 洛阳市| 泰安市| 德清县| 古蔺县| 灵台县| 赤城县| 库伦旗| 会宁县| 多伦县| 溆浦县| 仁布县| 怀宁县| 玛沁县| 清河县|