未将对象引用设置到对象的实例。急啊~~~~~~~~~~
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 34: Dim sqlconn As SqlConnection
行 35: sqlconn = New SqlConnection(constr)
行 36: sqlconn.Open()
行 37: Dim daohang As SqlCommand
行 38: Dim daohangreader As SqlDataReader
====================
Imports System.Data.SqlClient
Imports System.Data
Public Class top
Inherits System.Web.UI.UserControl
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
'Protected root As String = ConfigurationSettings.AppSettings( "webroot ")
Protected webtitle As String = ConfigurationSettings.AppSettings( "webtitle ")
Private constr As String = ConfigurationSettings.AppSettings( "app_connstr ")
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Page.IsPostBack Then
Dim sqlconn As SqlConnection
sqlconn = New SqlConnection
sqlconn = New SqlConnection(constr)
sqlconn.Open()
Dim daohang As SqlCommand
Dim daohangreader As SqlDataReader
daohang = New SqlCommand( "select Video_TypeName,Video_TypeID from tb_VideoType ", sqlconn)
daohangreader = daohang.ExecuteReader()
While daohangreader.Read
Label1.Text += "| <A href= 'list.aspx?type_id= " + daohangreader.Item( "Video_TypeID ").ToString + " '> " + daohangreader.Item( "Video_TypeName ").ToString + " </a> "
End While
daohangreader.Close()
sqlconn.Close()
End If
End Sub
End Class
[解决办法]
行 34: Dim sqlconn As SqlConnection
行 35: sqlconn = New SqlConnection(constr)
好象是定义了两次啊。
[解决办法]
VB太差,不过你这里改改看
Dim sqlconn As SqlConnection
sqlconn = New SqlConnection
sqlconn = New SqlConnection(constr)
sqlconn.Open()
改为
SqlConnection sqlconn = New SqlConnection(constr)