The event hancler below doesn't work in VWD 2010 Express. A duplicate data causes an error but it stops in the Business Logic Layer. It works fine in Visual Studio 2008. Please help if I am missing something?
Protected Sub ObjectDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles ObjectDataSource1.Inserted If e.Exception IsNot Nothing Then If e.Exception.InnerException IsNot Nothing Then Label1.Text = e.Exception.InnerException.Message e.ExceptionHandled = True End If End If End Sub
The ODS Control:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="InsertPerson" SelectMethod="GetPerson" TypeName="Person"> <SelectParameters> <asp:QueryStringParameter Name="id" QueryStringField="id" Type="Int32" /> </SelectParameters> <InsertParameters> <asp:Parameter Name="PersonName" Type="String" /> </InsertParameters> </asp:ObjectDataSource>
The BLL:
Public Class Person ... Public Shared Function InsertPerson(ByVal personName As String) As Integer Return SqlProvider.AddPerson(personName) End Function Public Shared Function GetPerson(ByVal id As Integer) As Person Return SqlProvider.GetPerson(id) End Function End Class
The DAL:
Public Class SqlProvider Public Shared Function AddPerson(ByVal name As String) As Integer Dim cn As SqlConnection = New SqlConnection( _ ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString) Dim cmd As SqlCommand = New SqlCommand("INSERT INTO person(name) VALUES(@name)", cn) cmd.Parameters.AddWithValue("@name", name) cn.Open() Return cmd.ExecuteNonQuery() End Function ... End Class
Execution stops in the line (DAL):
Return cmd.ExecuteNonQuery()
PLEASE HELP! I'm stuck!