... 코드도움말 : 오류 = NullReferenceException이 사용자 코드에 의해 처리되지 않은했다
오류가 줄에서 발생하는 ... 오류까지 정상적으로 작동합니다. SqlDataSource3.UpdateParameters를 ("TechID")의 DefaultValue()
Imports System.Data
Partial Class IncidentAssignment
Inherits System.Web.UI.Page
Public incidentRow As DataRowView
Public technicianRow As DataRowView
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Check to see if a incident has been selected
If GridView1.SelectedIndex = -1 Then
Button1.CommandName = ""
lblmessage.Text = "You must select an incident."
Else
Button1.CommandName = "NextView"
lblmessage.Text = ""
End If
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
'Check to see if a incident has been selected
If GridView2.SelectedIndex = -1 Then
Button3.CommandName = ""
lblmessage2.Text = "You must select a technician."
Else
Button3.CommandName = "NextView"
lblmessage2.Text = ""
'Create second DataView
Dim techniciansTable As DataView = CType(SqlDataSource2.Select(DataSourceSelectArguments.Empty), DataView)
'Save the selected technician data row
'To the DataRowView object and to session state
technicianRow = techniciansTable(GridView2.SelectedIndex)
Session("Technician") = technicianRow
'Create DataView
Dim incidentsTable As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
'Save PageIndex and PageSize to variables.
Dim pageIndex As Integer = GridView1.PageIndex
Dim pageSize As Integer = GridView1.PageSize
'Calculate the value of the SelectedIndex
Dim selectedIndex As Integer = (pageIndex * pageSize) + GridView1.SelectedIndex
'Save the selected data row to the DataRowView
'object and to session state
incidentRow = incidentsTable(selectedIndex)
Session("Incident") = incidentRow
'Display output from the two DataRowView objects
Label1.Text = incidentRow("Name")
Label2.Text = incidentRow("ProductCode")
Label3.Text = technicianRow("Name")
End If
End Sub
Public Sub btnAssign_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAssign.Click
'Assign data from session state to
'the two DataRowView objects
***ERROR technicianRow = CType(Session("Technician"), DataRowView)
incidentRow = CType(Session("Incident"), DataRowView)
'Update the value of the two parameters to be
'used to store new information about the
'assigned technician
SqlDataSource3.UpdateParameters("TechID").DefaultValue() = CInt(technicianRow("TechID"))
SqlDataSource3.UpdateParameters("IncidentID").DefaultValue() = CInt(incidentRow("IncidentID"))
'Trap errors
Try
'Update the table.
SqlDataSource3.Update()
'Unselect the two GridView controls
GridView1.SelectedIndex = -1
GridView2.SelectedIndex = -1
'Rebind the GridView controls
GridView1.DataBind()
GridView2.DataBind()
'Move to the first view
MultiView1.ActiveViewIndex = 0
Catch ex As Exception
Session("Exception") = ex
Session("Page") = "~/Admin/IndicentAssignment.aspx"
Response.Redirect("~/ErrorMessage.aspx")
End Try
End Sub
Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
End Sub
End Class
질문의 코딩 부분을 올바르게 편집하십시오. –