trycatch.aspx
来自「asp.net技术内幕的书配源码」· ASPX 代码 · 共 35 行
ASPX
35 行
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="C#" runat=server>
void Page_Load(Object sender , EventArgs e)
{
SqlConnection conNorthwind;
SqlCommand cmdSelect;
conNorthwind = new SqlConnection( @"Server=localhost;Integrated Security=SSPI;Database=Northwind;Connection TimeOut=15" );
cmdSelect = new SqlCommand( "select * from Products", conNorthwind );
try {
conNorthwind.Open();
dgrdProducts.DataSource = cmdSelect.ExecuteReader();
dgrdProducts.DataBind();
conNorthwind.Close();
}
catch (Exception Ex)
{
Response.Write( "We're sorry, we are experiencing technical problems..." );
}
}
</script>
<html>
<head><title>TryCatch.aspx</title></head>
<body>
<asp:DataGrid
ID="dgrdProducts"
Runat="Server" />
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?