日期:2014-05-19  浏览次数:20450 次

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

源错误:  


行   38:                   With   New   Business.R_Article_Info
行   39:                           Xtemp   =   .ArticleCount
行   40:                           Me.LabelArticle.Text   =   Xtemp.Tables(0).Rows.Count
行   41:                   End   With
行   42:                   '统计本日发表的文章数目
 


源代码:

                Dim   S   As   New   Comm.S_Article_Info
                Dim   Xtemp   As   New   System.Data.DataSet
                '统计有多少文章信息
                With   New   Business.R_Article_Info
                        Xtemp   =   .ArticleCount
                        Me.LabelArticle.Text   =   Xtemp.Tables(0).Rows.Count
                End   With
                '统计本日发表的文章数目
                With   New   Business.R_Article_Info
                        S.Article_Time   =   Date.Now.Date
                        Xtemp   =   .TodayCount(S)
                        Me.LabelTodayCount.Text   =   Xtemp.Tables(0).Rows.Count
                End   With
                '统计文章的浏览次数
                With   New   Business.R_Article_Info
                        Me.LabelCount.Text   =   .AllCount()
                End   With


------解决方案--------------------
根据你出的错误,很明显是dataset里面没有表,不过要解决这个问题也可以先判断下xtemp里面有没有表,lz看行不:
if Xtemp.Tables.Count> 0 then
Me.LabelArticle.Text = Xtemp.Tables(0).Rows.Count.Tostring() //试下这里要不要转换为字符型,没搞过vb.net^_^
else
Me.LabelArticle.Text = 0 //这里也一样,看下类型
end