I am getting an error while I am working through a asp.net 2.0 website tutorial
it is for the 11th chapter of the book where i am trying to update an employees address.
Partial Class AddressBook
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGrid()
End If
End Sub
Protected Sub employeeDetails_ItemUpdated( _
ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) _
Handles employeeDetails.ItemUpdated
Dim employeeid As Integer = employeeDetails.DataKey.Value
Dim newAddresstextbox As TextBox = employeeDetails.FindControl("editaddresstextbox")
Dim newcitytextbox As TextBox = employeeDetails.FindControl("editcitytextbox")
Dim newstatetextbox As TextBox = employeeDetails.FindControl("editstatetextbox")
Dim newziptextbox As TextBox = employeeDetails.FindControl("editziptextbox")
Dim newhomephonetextbox As TextBox = employeeDetails.FindControl(" editHomePhoneTextBox")
Dim newhextensiontextbox As TextBox = employeeDetails.FindControl(" editextensionTextBox")
Dim newaddress As String = newAddresstextbox.Text
Dim newcity As String = newcitytextbox.Text
Dim newstate As String = newstatetextbox.Text
Dim newzip As String = newziptextbox.Text
Dim newhomephone As String = newhomephonetextbox.Text
Dim newextension As String = newhextensiontextbox.Text
Dim comm As SqlCommand
Dim Conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\dorknozzle.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
comm = New SqlCommand("updateemployeedetails", Conn)
comm.CommandType = Data.CommandType.StoredProcedure
comm.Parameters.Add("@employeeid", Data.SqlDbType.Int)
comm.Parameters("@employeeid").Value = employeeid
comm.Parameters.Add("@newaddress", Data.SqlDbType.NVarChar, 50)
comm.Parameters("@newaddress").Value = newaddress
comm.Parameters.Add("@newcity", Data.SqlDbType.NVarChar, 50)
comm.Parameters("@newcity").Value = newcity
Try
Conn.Open()
comm.ExecuteNonQuery()
Finally
Conn.Close()
End Try
employeeDetails.ChangeMode(DetailsViewMode.ReadOnly)
BindGrid()
BindDetails()
End Sub
Private Sub BindGrid()
' Define data objects
'Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
' Read the connection string from Web.config
Dim Conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\dorknozzle.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
' Initialize connection
'conn = New SqlConnection(connectionString)
' Create command
comm = New SqlCommand( _
"SELECT EmployeeID, Name, City, State, MobilePhone " & _
"FROM Employees", conn)
' Enclose database code in Try-Catch-Finally
Try
' Open the connection
conn.Open()
' Execute the command
reader = comm.ExecuteReader()
' Fill the grid with data
grid.DataSource = reader
grid.DataKeyNames = New String() {"EmployeeID"}
grid.DataBind()
' Close the reader
reader.Close()
Finally
' Close the connection
conn.Close()
End Try
End Sub
Protected Sub grid_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles grid.SelectedIndexChanged
BindDetails()
End Sub
Private Sub BindDetails()
' Obtain the index of the selected row
Dim selectedRowIndex As Integer = grid.SelectedIndex
' Read the employee ID
Dim employeeId As Integer = _
grid.DataKeys(selectedRowIndex).Value
' Define data objects
'Dim conn As SqlConnection
Dim comm As SqlCommand
Dim reader As SqlDataReader
' Read the connection string from Web.config
Dim Conn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\dorknozzle.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
' Initialize connection
'conn = New SqlConnection(connectionString)
' Create command
comm = New SqlCommand( _
"SELECT EmployeeID, Name, Address, City, State, Zip, " & _
"HomePhone, Extension FROM Employees " & _
"WHERE EmployeeID=@EmployeeID", conn)
' Add the EmployeeID parameter
comm.Parameters.Add("EmployeeID", Data.SqlDbType.Int)
comm.Parameters("EmployeeID").Value = employeeId
' Enclose database code in Try-Catch-Finally
Try
' Open the connection
conn.Open()
' Execute the command
reader = comm.ExecuteReader()
' Fill the grid with data
employeeDetails.DataSource = reader
employeeDetails.DataKeyNames = New String() {"EmployeeID"}
employeeDetails.DataBind()
' Close the reader
reader.Close()
Finally
' Close the connection
conn.Close()
End Try
End Sub
Protected Sub employeeDetails_ModeChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewModeEventArgs) Handles employeeDetails.ModeChanging
' Change current mode to the selected one
employeeDetails.ChangeMode(e.NewMode)
' Rebind the grid
BindDetails()
End Sub
End Class
error
The DetailsView 'employeeDetails' fired event ItemUpdating which wasn't handled.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The DetailsView 'employeeDetails' fired event ItemUpdating which wasn't handled.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Bookmarks