首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

未将对象引用设置到对象的实例,该怎么解决

2012-01-10 
未将对象引用设置到对象的实例ImportsSystem.DataImportsSystem.Data.OleDbPublicClassrelationInheritsSy

未将对象引用设置到对象的实例
Imports   System.Data
Imports   System.Data.OleDb
Public   Class   relation
        Inherits   System.Web.UI.Page

#Region   "   Web   窗体设计器生成的代码   "

        '该调用是   Web   窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()>   Private   Sub   InitializeComponent()

        End   Sub
        Protected   WithEvents   lbllist   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
        Private   connectionstring   As   String   =   "provider=sqloledb.1;   data   source=localhost;   initial   catalog=pubs;   integrated   security=sspi "
        Private   Sub   Page_Load(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   MyBase.Load
                '在此处放置初始化页的用户代码
                If   Me.IsPostBack   =   False   Then
                        createlist()
                End   If
        End   Sub
        Private   Sub   createlist()
                Dim   selectsql   As   String
                selectsql   =   "select   au_lname,au_fname,au_id   from   authors "
                Dim   con   As   New   OleDbConnection(connectionstring)
                Dim   cmd   As   New   OleDbCommand(selectsql,   con)
                Dim   adapter   As   New   OleDbDataAdapter(cmd)
                Dim   dspubs   As   New   DataSet

                Try
                        con.Open()
                        adapter.Fill(dspubs,   "authors ")
                        cmd.CommandText   =   "select   au_id,title_id   from   titleauthor "
                        adapter.Fill(dspubs,   "titleauthor ")



                        cmd.CommandText   =   "select   title_id,title   from   titles "
                        adapter.Fill(dspubs,   "titles ")

                Catch   err   As   Exception
                        lbllist.text   =   "error   reading   list   of   names. "
                        lbllist.text   &=   err.Message
                Finally
                        If   (Not   con   Is   Nothing)   Then
                                con.Close()
                        End   If
                End   Try
                Dim   titles_titleauthor   As   DataRelation
                Dim   authors_titleauthor   As   DataRelation
                titles_titleauthor   =   New   DataRelation( " ",   dspubs.Tables( "titles ").Columns( "title_id "),   dspubs.Tables( "titleauthor ").Columns( "title_id "))
                authors_titleauthor   =   New   DataRelation( " ",   dspubs.Tables( "authors ").Columns( "au_id "),   dspubs.Tables( "titleauthor ").Columns( "au_id "))

                dspubs.relations.add(titles_titleauthor)
                dspubs.relations.add(authors_titleauthor)

                Dim   rowauthor,   rowtitleauthor,   rowtitle   As   DataRow

                For   Each   rowauthor   In   dspubs.tables( "authors ").rows

                        lbllist.Text   &=   " <br> <b> "   &   rowauthor( "au_fname ")
                        lbllist.Text   &=   " "   &   rowauthor( "au_lname ")   &   " </b> <br> "
                        For   Each   rowtitleauthor   In   rowauthor.GetChildRows(authors_titleauthor)
                                For   Each   rowtitle   In   rowtitleauthor.GetParentRows(titles_titleauthor)
                                        lbllist.Text   &=   "&nbsp;&nbsp; "
                                        lbllist.Text   &=   rowtitle( "title ")   &   " <br> "



                                Next
                        Next
                Next
        End   Sub

End   Class


行   57:                   Dim   titles_titleauthor   As   DataRelation
行   58:                   Dim   authors_titleauthor   As   DataRelation
行   59:                   titles_titleauthor   =   New   DataRelation( " ",   dspubs.Tables( "titles ").Columns( "title_id "),   dspubs.Tables( "titleauthor ").Columns( "title_id "))
行   60:                   authors_titleauthor   =   New   DataRelation( " ",   dspubs.Tables( "authors ").Columns( "au_id "),   dspubs.Tables( "titleauthor ").Columns( "au_id "))
行   61:  


未将对象引用设置到对象的实例!

高手帮我看看,谢谢!

[解决办法]
行 57: Dim titles_titleauthor As DataRelation
行 58: Dim authors_titleauthor As DataRelation
行 59: titles_titleauthor = New DataRelation( " ", dspubs.Tables( "titles ").Columns( "title_id "), dspubs.Tables( "titleauthor ").Columns( "title_id "))
行 60: authors_titleauthor = New DataRelation( " ", dspubs.Tables( "authors ").Columns( "au_id "), dspubs.Tables( "titleauthor ").Columns( "au_id "))
行 61:

这几行出错?貌似没问题啊 看看IDE停在哪
[解决办法]
Dim titles_titleauthor As DataRelation = New DataRelation( " ", dspubs.Tables( "titles ").Columns( "title_id "), dspubs.Tables( "titleauthor ").Columns( "title_id "))
Dim authors_titleauthor As DataRelation = New DataRelation( " ", dspubs.Tables( "authors ").Columns( "au_id "), dspubs.Tables( "titleauthor ").Columns( "au_id "))

改成这样

热点排行