2011-05-11 66 views
0

任何帮助,将不胜感激...代码工作,直到干净错误...帮助:错误=的NullReferenceException是由用户代码未处理

错误存在的在行:SqlDataSource3.UpdateParameters(“TechID”)默认值() = CINT(technicianRow( “TechID”))

这里充满VB代码:

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 
+0

正确编辑问题的编码部分。 – 2011-05-11 05:21:38

回答

0

从” .DefaultValue()

你有帕拉姆删除括号在页面的sqldatasource中定义的eters?

 
UpdateParameters> 
       <asp:Parameter Name="SomeName" Type="String" /> 
       <asp:Parameter Name="SomeDescription" Type="String" /> 
      </UpdateParameters> 
+0

试过......不行......在同一行上出现同样的错误......有没有其他想法? – 2011-05-11 05:41:45

+0

具体的错误是什么? – 2011-05-11 05:58:26

相关问题