Need help with Datalist Edit Command
-
I need a little help with some code I'm working on. I have a Datalist control that is throwing the following expeption. ------------------------------------------------------------------------ Object reference not set to an instance of an object. 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.NullReferenceException: Object reference not set to an instance of an object. ------------------------------------------------------------------------ Here is my code.
Sub Edit_Command(ByVal sender As Object, ByVal e As DataListCommandEventArgs) Handles DataList.EditCommand DataList.EditItemIndex = CType(e.Item.ItemIndex, Integer) Dim strDate As String = "" Dim strAssignments As String = "" Dim strSchool As String = "" Dim strProgramme As String = "" Dim strSubject As String = "" Dim strCity As String = "" Dim strState As String = "" Dim strReason As String = "" Dim reader As SqlDataReader Dim cmd As New SqlCommand("SELECT * FROM tblVolDeclinedMissedCanceledAssignments WHERE VolunteerId=" & VolunteerId() & " AND Id=" & e.CommandArgument, cn) cmd.CommandType = Data.CommandType.Text Try cn.Open() reader = cmd.ExecuteReader() While reader.Read strDate = IIf(IsDBNull(reader("Date")), "", reader("Date")) strAssignments = IIf(IsDBNull(reader("Assignment")), "", reader("Assignment")) strSchool = IIf(IsDBNull(reader("SchoolVenue")), "", reader("SchoolVenue")) strProgramme = IIf(IsDBNull(reader("Programme")), "", reader("Programme")) strSubject = IIf(IsDBNull(reader("Subject")), "", reader("Subject")) strCity = IIf(IsDBNull(reader("City")), "", reader("City")) strState = IIf(IsDBNull(reader("StateProvince")), "", reader("StateProvince")) strReason = IIf(IsDBNull(reader("Reason")), "", reader("Reason")) End While Catch ex As Exception Throw New ApplicationException(ex.Message) Finally cn.Close() End Try CType(e.Item.FindControl("rdpEditDate"), Telerik.WebControls.RadDatePicker).SelectedDate = strDate CType(e.Item.FindControl("ddlEditAssignments