疯掉了,平时这么写都是可以的,今天。。。。。兄弟们帮我看看!!!!
代码:
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