C# 示例:
1. Hello World:
@{
var message = "Hello, World!";
}
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>@message</h1>
</body>
</html>
2. 数据库连接和显示:
@{
var db = Database.Open("YourConnectionString");
var data = db.Query("SELECT * FROM YourTable");
}
<!DOCTYPE html>
<html>
<head>
<title>Database Example</title>
</head>
<body>
<h2>Database Records</h2>
<ul>
@foreach (var row in data)
{
<li>@row.ColumnName</li>
}
</ul>
</body>
</html>
VB.NET 示例:
1. Hello World:
@Code
Dim message As String = "Hello, World!"
End Code
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>@message</h1>
</body>
</html>
2. 数据库连接和显示:
@Code
Dim db = Database.Open("YourConnectionString")
Dim data = db.Query("SELECT * FROM YourTable")
End Code
<!DOCTYPE html>
<html>
<head>
<title>Database Example</title>
</head>
<body>
<h2>Database Records</h2>
<ul>
@For Each row In data
<li>@row.ColumnName</li>
Next
</ul>
</body>
</html>
在这些示例中:
- @{ ... } 或 @Code ... End Code 块用于包含服务器端代码。
- @ 符号用于输出变量或执行表达式。
- Database.Open 用于连接到数据库。
- db.Query 用于执行 SQL 查询。
请替换示例中的数据库连接字符串和查询,以适应你的具体情况。这些示例只是基本的演示,你可以根据项目的需求添加更多功能和复杂性。
转载请注明出处:http://www.pingtaimeng.com/article/detail/6541/ASP.NET