如何在asp+中使用jscript.net这才是我们关键的问题。我们将通过一个例子来说明这个问题。
访问sqlserver数据库
第一个aps+例子是使用jscript.net和.net的数据访问类来访问sqlserver数据库,
这里我还将使用大家熟悉的<% %>格式来编写,访问pubs中的authors表,我知道这很简单但是它可以体现一些新的特性。
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sql" %>
<%@ language="jscript" %>
<link rel="stylesheet" type="text/css" href="style.css">
<%
// 设置数据库连接
var myconnection:sqlconnection = new sqlconnection("server=scripting;uid=sa;pwd=;database=pubs");
// 执行查询
var mycommand:sqldatasetcommand = new sqldatasetcommand("select * from authors", myconnection);
// 声明变量
var ds:dataset = new dataset();
var mytable:datatable
var mycolumns:columnscollection
var mycol:datacolumn
var myrows:rowscollection
var myrow:datarow
// 通过filldataset方法获取数据
mycommand.filldataset(ds, "authors");
mytable = ds.tables[0]
%>
<h1>
<%=ds.tables[0].tablename%>
</h1>
<br>
<table>
<thead>
<tr>
<%
//在表格的最上面输出字段名
mycolumns = mytable.columns
for (mycol in mycolumns)
{
%>
<th class="spec">
<%=mycol.columnname%>
</th>
<%
}
%>
</tr>
</thead>
<%
// 输出所有的纪录
myrows = mytable.rows
for (myrow in myrows)
{
%>
<tr>
<%
for(var i:int=0;i<mycolumns.count;i++)
{
%>
<td class="spec">
<%=myrow[i]%>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器