利用RowDeleted事件捕捉SQL错误(c#,vb.net)

作者:袖梨 2022-06-25

利用RowDeleted事件捕捉SQL错误(c#)

protected void SqlDataSource1_Deleted(object sender, SqlDataSourceStatusEventArgs e)
{
if (e.Exception != null)
{
this.lblErrorMessage.Text = e.Exception.Message;
e.ExceptionHandled = true;
}
}



Untitled Page




asp教程:GridView ID="GridView1" Runat="server" DataSourceID="SqlDataSource1"
DataKeyNames="CustomerID" AutoGenerateColumns="False"
AllowSorting="True" AllowPaging="True"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="true" OnRowDeleted="GridView1_RowDeleted">

FirstPageText="Go to the first page"
LastPageText="Go to the last page" Mode="NextPreviousFirstLast">


SortExpression="CustomerID" Visible="False">
DataNavigateUrlFields="CustomerID,Country" SortExpression="CompanyName"
DataNavigateUrlFormatString="http://www.y*ou*rS*erver.com/Customer.aspx?id={0}&country={1}"
DataTextField="CompanyName">

SortExpression="ContactName">
SortExpression="ContactTitle">
SortExpression="Address">
SortExpression="City">
DataField="Region" SortExpression="Region">
SortExpression="PostalCode">
SortExpression="Country">
SortExpression="Phone">
SortExpression="Fax">


SelectCommand="SELECT * FROM [Customers]"
ConnectionString=""
DataSourceMode="DataSet"
DeleteCommand="DELETE From Customers WHERE (CustomerID = @CustomerID)"
UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName,
[ContactName] = @ContactName, [ContactTitle] = @ContactTitle,
[Address] = @Address, [City] = @City, [Region] = @Region,
[PostalCode] = @PostalCode, [Country] = @Country, [Phone] = @Phone,
[Fax] = @Fax WHERE [CustomerID] = @original_CustomerID" OnDeleted="SqlDataSource1_Deleted">


















File: Web.config




connectionString="Data Source=localhostSQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"
providerName="System.Data.SqlClient" />































vb.net版

http://www.w***3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Protected Sub SqlDataSource1_Deleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs)
If (e.Exception IsNot Nothing) Then
Me.lblErrorMessage.Text = e.Exception.Message
e.ExceptionHandled = True
End If
End Sub

https://www.111cn.net /1999/xhtml" >


Untitled Page



Runat="server"
DataSourceID="SqlDataSource1"
DataKeyNames="CustomerID"
AutoGenerateColumns="False"
AllowSorting="True"
AllowPaging="True"
AutoGenerateEditButton="true"
AutoGenerateDeleteButton="true"
OnRowDeleted="GridView1_RowDeleted">

FirstPageText="Go to the first page"
LastPageText="Go to the last page"
Mode="NextPreviousFirstLast">


HeaderText="CustomerID"
DataField="CustomerID"
SortExpression="CustomerID"
Visible="False">
DataNavigateUrlFields="CustomerID,Country" SortExpression="CompanyName"
DataNavigateUrlFormatString=
"https://www.111cn.net/ Customer.aspx?id={0}&country={1}"
DataTextField="CompanyName">

SortExpression="ContactName">
SortExpression="ContactTitle">
SortExpression="Address">
SortExpression="City">
DataField="Region" SortExpression="Region">
SortExpression="PostalCode">
SortExpression="Country">
SortExpression="Phone">
SortExpression="Fax">


SelectCommand="SELECT * FROM [Customers]"
ConnectionString=""
DataSourceMode="DataSet"
DeleteCommand="DELETE From Customers WHERE (CustomerID = @CustomerID)"
UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName,
[ContactName] = @ContactName, [ContactTitle] = @ContactTitle,
[Address] = @Address, [City] = @City, [Region] = @Region,
[PostalCode] = @PostalCode, [Country] = @Country, [Phone] = @Phone,
[Fax] = @Fax WHERE [CustomerID] = @original_CustomerID" OnDeleted="SqlDataSource1_Deleted">


















File: Web.config




connectionString="Data Source=localhostSQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"
providerName="System.Data.SqlClient" />































相关文章

精彩推荐