标题:System.NullReferenceException 未将对象引用设置到对象的实例
取消只看楼主
biwysh
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-13
 问题点数:0 回复次数:2 
System.NullReferenceException 未将对象引用设置到对象的实例
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 9:      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
行 10:         If Page.IsPostBack Then
行 11:             Dim conn As ConnDB = New ConnDB()
行 12:             Dim strSQL As String
行 13:             conn.DBOpen()
 

源文件: D:\Backup\我的文档\Visual Studio 2005\WebSites\regedit\regedit.aspx.vb    行: 11

堆栈跟踪:


[NullReferenceException: 未将对象引用设置到对象的实例。]
   ConnDB..ctor() +48
   regedit.Page_Load(Object sender, EventArgs e) in D:\Backup\我的文档\Visual Studio 2005\WebSites\regedit\regedit.aspx.vb:11
   System.Web.UI.Control.OnLoad(EventArgs e) +80
   System.Web.UI.Control.LoadRecursive() +49
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3750

 


--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; 版本:2.0.50727.1433
搜索更多相关主题的帖子: 实例 System 对象 设置 
2008-05-22 13:24
biwysh
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-13
得分:0 
各位老师帮忙看看,我是初学者,老师让弄一个注册的网页,这点出错了,搞不明白ConnDB()
是一个vb的类就是把接数据库一些函数封装到这个类里
Imports Microsoft.VisualBasic
Imports System.Data.OleDb
Imports System.Data
Public Class ConnDB
    Inherits System.Web.UI.Page

    Private connStr As String
    Private objCon As OleDbConnection
    Private objCmd As OleDbCommand
    Private objDS As Data.DataSet
    Private objDR As OleDbDataReader
    Private objDA As OleDbDataAdapter

   
    Public Sub New()
        connStr = "Provider=" & System.Web.Configuration.WebConfigurationManager.ConnectionStrings("servername").ProviderName
        connStr &= "Data Source=" & System.Web.HttpContext.Current.Server.MapPath(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("severname").ConnectionString())
        objCon = New OleDbConnection(connStr)
    End Sub
    Public Sub DBOpen()
        '打开数据库连接
        objCon.Open()
    End Sub
    Public Sub DBclose()  '关闭数据库
        Try
            objCon.Close()
        Catch ex As Exception
            objCon.Dispose()
        End Try
    End Sub
  
    Public Function getDataSet(ByVal sql As String) As DataSet
        If objCon.State = ConnectionState.Closed Then
            DBOpen()
        End If
        objDA = New OleDbDataAdapter(sql, objCon)
        objDS = New DataSet()
        objDA.Fill(objDS, "regedit")
        Return objDS
    End Function
2008-05-22 13:27
biwysh
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-9-13
得分:0 
下面是主页的代码,高手帮忙分析一下,急用
Imports System.Data.OleDb
Imports System.Data
Imports Microsoft.VisualBasic
Partial Class regedit
    Inherits System.Web.UI.Page

 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Page.IsPostBack Then
            Dim conn As ConnDB = New ConnDB()
            Dim strSQL As String
            conn.DBOpen()
            strSQL = "SELECT * FROM regedit"
            Dim datast As DataSet = New DataSet()
            datast = conn.getDataSet(strSQL)
            Dim objDTrow As DataRow
            objDTrow = datast.Tables("regedit").NewRow
            objDTrow("id") = id.Text
            objDTrow("pass") = pass.Text
            Dim email As String
            email = email1.Text & "@" & email2.Text
            objDTrow("email") = email
            datast.Tables("regedit").Rows.Add(objDTrow)
            conn.DBclose()
        End If

    End Sub
End Class
2008-05-22 13:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-215597-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.153980 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved