Imports System.Data
Imports System.Data.SqlClient
Public Class read
Inherits System.Web.UI.Page
Dim conn As SqlConnection = New SqlConnection("database=new;uid=sa;pwd=;server=127.0.0.1")
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents printScript As System.Web.UI.HtmlControls.HtmlGenericControl
Dim ds As New DataSet
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents TimeLabel As System.Web.UI.WebControls.Label
Protected WithEvents AuthorLabel As System.Web.UI.WebControls.Label
Protected WithEvents PreviousLink As System.Web.UI.WebControls.Literal
Protected WithEvents NextLink As System.Web.UI.WebControls.Literal
Protected WithEvents numPages As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents Label1 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 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Session("pass") <> "ok" Then
Response.Redirect("login.aspx")
End If
Dim str1 As String = "select * from message1 where caption='" & Session("caption") & "'"
Dim da As New SqlDataAdapter(str1, conn)
Dim ds As New DataSet
da.Fill(ds, "usertable")
Label1.Text = RTrim(ds.Tables("message1").Rows(0).Item("caption"))
TimeLabel.Text = RTrim(ds.Tables("message1").Rows(0).Item("date1"))
AuthorLabel.Text = RTrim(ds.Tables("message1").Rows(0).Item("name"))
Label2.Text = RTrim(ds.Tables("message1").Rows(0).Item("meat"))
End Sub
End Class
“/WebApplication1”应用程序中的服务器错误。
--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 43: Dim ds As New DataSet
行 44: da.Fill(ds, "usertable")
行 45: Label1.Text = RTrim(ds.Tables("message1").Rows(0).Item("caption"))
行 46: TimeLabel.Text = RTrim(ds.Tables("message1").Rows(0).Item("date1"))
行 47: AuthorLabel.Text = RTrim(ds.Tables("message1").Rows(0).Item("name"))