疯掉了,平时这么写都是可以的,今天。。。。。兄弟们帮我看看!!!!

yqyzzy 2004-10-07 08:19:27
代码:

Imports System.io
Imports System.Data
Imports System.Data.OleDb
Public Class index
Inherits System.Web.UI.Page
Public x, xx As Integer
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
#Region " Web 窗体设计器生成的代码 "

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

End Sub
Protected WithEvents DataList1 As System.Web.UI.WebControls.DataList
Protected WithEvents DataList2 As System.Web.UI.WebControls.DataList
Protected WithEvents DataList3 As System.Web.UI.WebControls.DataList
Protected WithEvents DataList4 As System.Web.UI.WebControls.DataList
Protected WithEvents DataList5 As System.Web.UI.WebControls.DataList
Protected WithEvents DataList6 As System.Web.UI.WebControls.DataList

'注意: 以下占位符声明是 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 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
tongji()
If Not Page.IsPostBack Then
show(DataList1, "vb.net")
show(DataList2, "asp.net")
show(DataList3, "sql")
show(DataList4, "access")
show(DataList5, "shenghuo")
show(DataList6, "qita")

'diaocha()
End If
End Sub
Private Sub show(ByVal datalistx As System.web.ui.webcontrols.DataList, ByVal str As String)
Dim con As New conn.conn
con.con3.Open()
Dim sql As String
Dim i As Integer
Dim dataset11 As New DataSet
sql = "select classid from class where classname='" & str & "'"
Dim cmd As New OleDbCommand(sql, con.con3)
i = Convert.ToInt32(cmd.ExecuteScalar)
sql = "select top 8 articleid,left(title,25) as 标题,left(shijian,10) as 时间 from wenzhang where classid=" & i & " order by classid"
Dim adpter As New OleDbDataAdapter(sql, con.con3)
adpter.Fill(dataset11, "xxx")
datalistx.DataSource = dataset11.Tables(0).DefaultView
datalistx.DataKeyField = dataset11.Tables(0).Columns(0).ToString
datalistx.DataBind()
dataset11 = Nothing
con.con3.Close()
End Sub
Sub diaocha()
Dim per(4) As Single
Dim k, i, j As Integer
Dim id(4) As String
Dim result(4) As String
Dim txtreader As StreamReader
Dim txtwriter As StreamWriter
Dim trecord, votefile As String
Dim sum As Single
k = CInt(Request.Form("toupiao"))
votefile = Server.MapPath("diaocha.txt")
txtreader = File.OpenText(votefile)
i = 0
Do
trecord = Trim(txtreader.ReadLine())
If trecord <> "" Then
id(i) = Left(trecord, 1)
result(i) = Trim(Right(trecord, Len(trecord) - 2))
If i = k Then
j = CLng(result(i)) + 1
result(i) = Trim(CStr(j))
End If
i = i + 1
End If
Loop Until trecord = ""
txtreader.Close()
txtwriter = File.CreateText(votefile)
For j = 0 To (i - 1)
sum += CLng(result(j))
txtwriter.WriteLine(id(j) & " " & result(j))
per(j) = CLng(result(j)) / sum
Next
txtwriter.Close()
End Sub
Sub tongji()
Dim sql1, sql2 As String
Dim con As New conn.conn
con.con3.Open()
sql1 = "SELECT count(articleid) FROM wenzhang WHERE articleid is not null"
Dim adapter1 As New OleDbCommand(sql1, con.con3)
x = Convert.ToInt32(adapter1.ExecuteScalar().ToString())
Label1.Text = x.ToString
con.con3.Close()
con.con3.Open()
sql2 = "select count(classid) from class where classid is not null"
Dim adapter2 As New OleDbCommand(sql2, con.con3)
xx = Convert.ToInt32(adapter2.ExecuteScalar().ToString())
Label2.Text = xx.ToString
con.con3.Close()
End Sub
End Class


错误提示:


“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

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

源错误:


行 102: Dim con As New conn.conn
行 103: con.con3.Open()
行 104: sql1 = "SELECT count(articleid) FROM wenzhang WHERE articleid is not null"
行 105: Dim adapter1 As New OleDbCommand(sql1, con.con3)
行 106: x = Convert.ToInt32(adapter1.ExecuteScalar().ToString())


源文件: D:\zyweb\index.aspx.vb 行: 104

...全文
90 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
famousun 2004-10-07
  • 打赏
  • 举报
回复
你跟踪一下,看看有没有取到值
没取到值,做什么都是没意义的
yqyzzy 2004-10-07
  • 打赏
  • 举报
回复
cancersyf(fengzhimei) (

还是不可以!!!!
cancersyf 2004-10-07
  • 打赏
  • 举报
回复
我想错误不应该在那句sql语句上,那仅仅是一个赋值语句,怎么会出现NullReferenceException类型的异常呢,好好看看你的程序,我觉得类似下面的语句比较可疑:

x = Convert.ToInt32(adapter1.ExecuteScalar().ToString())
yqyzzy 2004-10-07
  • 打赏
  • 举报
回复
顶一下!!!!


laihua(背着石头过河)
还是原来那个错误!!!!:(
laihua 2004-10-07
  • 打赏
  • 举报
回复
sql1 = "SELECT count(articleid) as count FROM wenzhang WHERE articleid is not null"改成這樣行不行

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧