當我運行下面的代碼它thows以下錯誤:錯誤 - 對象引用不設置到對象的實例
"Object reference not set to an instance of an object."
Protected Sub CreateUserWizard1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles CreateUserWizard1.Load
Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True")
Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT TOP 1 EmployeeId FROM a1_admins Order by Id DESC", SQLData)
Dim label11 As Label = CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Label11")
SQLData.Open()
Dim dtrReader As System.Data.SqlClient.SqlDataReader = cmdSelect.ExecuteReader()
If dtrReader.HasRows Then
While dtrReader.Read()
label11.Text = dtrReader("EmployeeId")
End While
End If
dtrReader.Close()
SQLData.Close()
End Sub
End Class
我該如何解決這個問題?
哪行代碼拋出異常?此外,如果您將其格式化爲代碼,則會更容易閱讀。 – Chaulky 2010-12-01 16:31:01
[對象引用未設置爲對象實例]的可能重複(http://stackoverflow.com/questions/548932/object-reference-not-set-to-an-instance-of-an-object) – Justin 2011-12-16 15:02:28