| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 710 人关注过本帖
标题:[求助]未将对象引用设置到对象的实例。
只看楼主 加入收藏
khl
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2006-4-30
收藏
 问题点数:0 回复次数:1 
[求助]未将对象引用设置到对象的实例。

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

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

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

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

源错误:

行 46:         DS.Clear()
行 47: DS = GetDataFromDB(sqlstr)
行 48: If DS.Tables(0).Rows.Count > 0 Then
行 49: sqlstr = "SELECT*FROM userID WHERE" & "(用户名='" & strID & " ') AND (密码='" & pwd & " ') "
行 50: Dim myDS As DataSet

源文件: C:\Inetpub\wwwroot\EMIS\WebfrmLogin.aspx.vb 行: 48

堆栈跟踪:

[NullReferenceException: 未将对象引用设置到对象的实例。]
EMIS.WebfrmLogin.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\EMIS\WebfrmLogin.aspx.vb:48
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277




Imports System


Imports System.Data
Imports System.Drawing
Imports System.Data.OleDb
Module ConnToDB
Public ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
Public ConnectStr As String = ConnStr & "Data Source=E:\寇换龙\data\student.mdb"
Public DataAdapter As OleDbDataAdapter
Public DataConnection As OleDbConnection
Public myDataSet As DataSet
Public Index As Integer
Public pepdom As Integer
Public No As String
Public Function GetDataFromDB(ByVal sqlstr As String) As DataSet
Try
Dim DataConnection As OleDbConnection
DataConnection.ConnectionString = ConnectStr
DataAdapter = New OleDbDataAdapter(sqlstr, DataConnection)
myDataSet = New DataSet
DataConnection.Open()
myDataSet.Clear()
DataAdapter.Fill(myDataSet)
DataConnection.Close()
If Not (myDataSet Is Nothing) Then
Return myDataSet
End If
Catch ex As Exception
Return Nothing
End Try
End Function
    Public Function UpdateDataBase(ByVal sqlstr As String) As Boolean
Dim sqlconn As New OleDbConnection(ConnectStr)
Try
Dim cmdTable As OleDbCommand = New OleDbCommand(sqlstr, sqlconn)
cmdTable.CommandType = CommandType.Text
sqlconn.Open()
cmdTable.ExecuteNonQuery()
sqlconn.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function
End Module

Public Class WebfrmLogin
Inherits System.Web.UI.Page
Public sqlstr As String
Public strID As String
Public pwd As String
Public DS As DataSet
Public table As String

#Region " Web 窗体设计器生成的代码 "
    '该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    End Sub
Protected WithEvents Image1 As System.Web.UI.WebControls.Image
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Image2 As System.Web.UI.WebControls.Image
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
'注意: 以下占位符声明是 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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
strID = Trim(Me.TextBox1.Text)
If strID = "" Then
Me.Label4.Text = "请输入登录的用户名称。"
Exit Sub
End If
pwd = Trim(Me.TextBox2.Text)
sqlstr = "SELECT*FROM userID WHERE" & "(用户名='" & strID & "') "
DS = New DataSet
DS.Clear()
DS = GetDataFromDB(sqlstr)
If DS.Tables(0).Rows.Count > 0 Then
sqlstr = "SELECT*FROM userID WHERE" & "(用户名='" & strID & " ') AND (密码='" & pwd & " ') "
Dim myDS As DataSet
myDS = New DataSet
myDS.Clear()
myDS = GetDataFromDB(sqlstr)
If myDS.Tables(0).Rows.Count > 0 Then
pepdom = myDS.Tables(0).Rows(0)("权限")
Me.Response.Redirect("http://localhost/EIMS//WebfrmMain.aspx")
Else
Me.Label4.Text = "输入的密码不正确,请重新输入密码。"
Me.TextBox2.Text = ""
End If
Else
Me.Label4.Text = "查无此人,请确认是否有该用户存在。"
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
End If
End Sub
End Class




版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573

[此贴子已经被作者于2006-5-5 10:30:54编辑过]

搜索更多相关主题的帖子: 实例 对象 堆栈 服务器 
2006-05-05 10:30
wugong
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2005-8-1
收藏
得分:0 
sqlstr = "SELECT * FROM userID WHERE 用户名='" & strID & "'"
2006-05-06 08:21
快速回复:[求助]未将对象引用设置到对象的实例。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012598 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved