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

我在做asp.net web应用程序的时候遇到了数据登录问题,请高手帮助一下,我真太郁闷了, 我已经做好几天,没有通过这个难关,希望大哥 大姐帮一忙,本人万分感谢 E-mail kouhuanlong@163.com QQ 149348137
Module ConnToDB
Public ConnStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
Public ConnectStr As String = ConnStr & "Data Source=C:\student.mdb"
Public DataAdapter As OleDbDataAdapter
Public DataConnection As OleDbConnection
Public DataSet As DataSet
Public Index As Integer
Public pepdom As Integer
Public No As String
Public Function GetDataFromDB(ByVal sqlstr As String) As DataSet
Try
DataConnection = New OleDbConnection
DataConnection.ConnectionString = ConnectStr
DataAdapter = New OleDbDataAdapter(sqlstr, DataConnection)
DataSet = New DataSet
DataSet.Clear()
DataAdapter.Fill(DataSet)
DataConnection.Close()
If Not DataSet Is Nothing Then
Return DataSet
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

#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


错提示是:

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

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

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

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

源错误:

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

源文件: c:\inetpub\wwwroot\EMIS\WebfrmLogin.aspx.vb 行: 47

堆栈跟踪:

[NullReferenceException: 未将对象引用设置到对象的实例。]
EMIS.WebfrmLogin.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\EMIS\WebfrmLogin.aspx.vb:47
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


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

[此贴子已经被作者于2006-5-3 15:14:06编辑过]

搜索更多相关主题的帖子: 数据库 
2006-05-03 15:10
seals
Rank: 1
等 级:新手上路
帖 子:141
专家分:0
注 册:2005-2-5
收藏
得分:0 
要么你写的查询语句有问题,要么返回是空,总之你要跟一下GetDataFromDB就明白了

说你哪,看了我那么多帖子都不回,好意思吗?! 觉得需要我帮助,请Q:496227096
2006-05-04 20:41
快速回复:[求助][求助]连接数据库出错
数据加载中...
 
   



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

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