不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
ASP.NET中引用类库示例
编辑:dnawo 日期:2008-05-15
一、不将代码放在单独的文件中的引用方法
1.VB
VB.aspx:
2.C#
CSharp.aspx:
可以看到,不将代码放在单独的文件中时,VB和C#对类库的引用方法是一样的!
二、将代码放在单独的文件中的引用方法
1.VB
VB.aspx:
VB.aspx.vb:
2.C#
CSharp.aspx:
CSharp.aspx.cs:
细心的你可能已经发现:.vb文件中引用的类库没有.cs文件中多,其实.vb也是有引用的,只是在创建VB类型的ASP.NET站点时,VS2005将常用类库的引用放在配置文件web.config中了:
经测试:将类库的引用放在web.config中时,不将代码放在单独的文件中,VB和C#都可以正常使用;将代码放在单独的文件中,VB可以正常使用,C#不能使用。
1.VB
VB.aspx:
复制内容到剪贴板
程序代码

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As SqlConnection = New SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)")
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("select top 1 username from dv_admin", conn)
Response.Write(cmd.ExecuteScalar())
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>VB不将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As SqlConnection = New SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)")
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("select top 1 username from dv_admin", conn)
Response.Write(cmd.ExecuteScalar())
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>VB不将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
2.C#
CSharp.aspx:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)");
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 username from dv_admin", conn);
Response.Write(cmd.ExecuteScalar());
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#不将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)");
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 username from dv_admin", conn);
Response.Write(cmd.ExecuteScalar());
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#不将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
可以看到,不将代码放在单独的文件中时,VB和C#对类库的引用方法是一样的!
二、将代码放在单独的文件中的引用方法
1.VB
VB.aspx:
复制内容到剪贴板
程序代码

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>VB将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>VB将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
VB.aspx.vb:
复制内容到剪贴板
程序代码

Imports System.Data.SqlClient
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As SqlConnection = New SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)")
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("select top 1 username from dv_admin", conn)
Response.Write(cmd.ExecuteScalar())
End Sub
End Class
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim conn As SqlConnection = New SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)")
conn.Open()
Dim cmd As SqlCommand = New SqlCommand("select top 1 username from dv_admin", conn)
Response.Write(cmd.ExecuteScalar())
End Sub
End Class
2.C#
CSharp.aspx:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CSharp.aspx.cs" Inherits="CSharp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>C#将代码放在单独的文件中</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
CSharp.aspx.cs:
复制内容到剪贴板
程序代码

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class CSharp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)");
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 username from dv_admin", conn);
Response.Write(cmd.ExecuteScalar());
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class CSharp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("uid=sa;password=sa;database=dvbbsnet;server=(local)");
conn.Open();
SqlCommand cmd = new SqlCommand("select top 1 username from dv_admin", conn);
Response.Write(cmd.ExecuteScalar());
}
}
细心的你可能已经发现:.vb文件中引用的类库没有.cs文件中多,其实.vb也是有引用的,只是在创建VB类型的ASP.NET站点时,VS2005将常用类库的引用放在配置文件web.config中了:
复制内容到剪贴板
程序代码

<system.web>
<pages>
<namespaces>
<clear />
<add namespace="System" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Specialized" />
<add namespace="System.Configuration" />
<add namespace="System.Text" />
<add namespace="System.Text.RegularExpressions" />
<add namespace="System.Web" />
<add namespace="System.Web.Caching" />
<add namespace="System.Web.SessionState" />
<add namespace="System.Web.Security" />
<add namespace="System.Web.Profile" />
<add namespace="System.Web.UI" />
<add namespace="System.Web.UI.WebControls" />
<add namespace="System.Web.UI.WebControls.WebParts" />
<add namespace="System.Web.UI.HtmlControls" />
</namespaces>
</pages>
</system.web>
<pages>
<namespaces>
<clear />
<add namespace="System" />
<add namespace="System.Collections" />
<add namespace="System.Collections.Specialized" />
<add namespace="System.Configuration" />
<add namespace="System.Text" />
<add namespace="System.Text.RegularExpressions" />
<add namespace="System.Web" />
<add namespace="System.Web.Caching" />
<add namespace="System.Web.SessionState" />
<add namespace="System.Web.Security" />
<add namespace="System.Web.Profile" />
<add namespace="System.Web.UI" />
<add namespace="System.Web.UI.WebControls" />
<add namespace="System.Web.UI.WebControls.WebParts" />
<add namespace="System.Web.UI.HtmlControls" />
</namespaces>
</pages>
</system.web>
经测试:将类库的引用放在web.config中时,不将代码放在单独的文件中,VB和C#都可以正常使用;将代码放在单独的文件中,VB可以正常使用,C#不能使用。
评论: 0 | 引用: 0 | 查看次数: 6506
发表评论
请登录后再发表评论!