本文介绍了空引用异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨先生我得到空引用异常。亲切的帮助



我的尝试:



Hi sir I am getting null reference exception. kindly help

What I have tried:

Protected Sub ddlstate_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlstate.SelectedIndexChanged
        If ddlfin_year.SelectedIndex = 0 Then
            ClientScript.RegisterStartupScript(Me.GetType, "msgg", "alert('Please select Financial Year');", True)
            ddlstate.SelectedIndex = 0
            Return
        End If
        If ddlmnth.SelectedIndex = 0 Then
            ClientScript.RegisterStartupScript(Me.GetType, "msgg", "alert('Please select Month');", True)
            ddlstate.SelectedIndex = 0
            Return
        End If
        con.Open()
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        Dim cmd As New SqlCommand
        Dim read As SqlDataReader



        cmd = New SqlCommand("Select Fin_Year,state_code,allocation from StateBrief_NSAP where Fin_Year='" & ddlfin_year.SelectedItem.Text & "' And   state_code='" & ddlstate.SelectedItem.Value & "'", con)
        da = New SqlDataAdapter(cmd)

        dt = New DataTable()

        da.Fill(dt)

        read = cmd.ExecuteReader()
        read.Read()
        If dt.Rows.Count > 0 Then
            While read.Read

                Dim allocation As String = CStr(read("allocation"))



                Session("alloc") = allocation






            End While
            txtAllocation.Text = Session("alloc").ToString()


            txtAllocation.Enabled = False
        Else


            txtAllocation.Enabled = True
            txtAllocation.Text = ""




        End If



        read.Close()



    End Sub

推荐答案



这篇关于空引用异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:09