2

这是按钮单击事件的代码;

  Protected Sub CompetenciesButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CompetenciesButton.Click
        Dim con As String = WebConfigurationManager.ConnectionStrings("foo").ToString()
        Dim selectedrow As String = Competencies.SelectedValue.ToString
        Dim s As String = "SELECT * from foo WHERE (" & selectedrow & " =1)"
        Dim DataAdapter As New SqlDataAdapter(s, con)
        Dim Result As New DataTable
        If Not IsNothing(DataAdapter) Then
            DataAdapter.Fill(Result)
            DataAdapter.Dispose()
        End If
        GV.DataSource = Result
        GV.DataBind()
        GV2.DataSource = Result
        GV2.DataBind()
    End Sub

这是堆栈:

[NullReferenceException: Object reference not set to an instance of an object.]
   administration_Search.CompetenciesButton_Click(Object sender, EventArgs e) +28
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746

VS2008 离线时一切正常,但发布后出现此错误。

谢谢。

4

1 回答 1

1

您的 WebConfiguration 在 dev 和 live 上是否相同?

如果您缺少实时服务器上的foo连接字符串,则该con对象将设置为 null。

如果你仍然无法捕获它,那么尝试包含一个 try/catch 块,progress在 try 之外设置一个字符串变量,在逻辑中的每一行更新它,并将错误与progress. 这应该有助于缩小发生的范围。

于 2010-03-04T13:07:22.657 回答