sqlexception.aspx
来自「asp.net技术内幕的书配源码」· ASPX 代码 · 共 42 行
ASPX
42 行
<%@ 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 BadTable", conNorthwind );
try
{
conNorthwind.Open();
dgrdProducts.DataSource = cmdSelect.ExecuteReader();
dgrdProducts.DataBind();
conNorthwind.Close();
}
catch (SqlException objException)
{
foreach (SqlError objError in objException.Errors)
{
Response.Write( "<li>" + objError.Message );
}
}
}
</Script>
<html>
<head><title>SqlException.aspx</title></head>
<body>
<asp:DataGrid
ID="dgrdProducts"
Runat="Server" />
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?