asp.net 用户代码未处理OleDbException。如何处理?

ImportsSystem.Data.OleDbPartialClassDefault2InheritsSystem.Web.UI.PagePublicSubcheck_... Imports System.Data.OleDb
Partial Class Default2
Inherits System.Web.UI.Page

Public Sub check_log1()
Dim myconnection As Data.OleDb.OleDbConnection
myconnection = New Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("db1.mdb"))
Dim searchcmd As String
searchcmd = "select * from student where 姓名='" & user_id.Text & "' and 学号='" & password.Text & "'"
Dim mycommand As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand(searchcmd, myconnection)
mycommand.connection.open()
Dim myreader As Data.OleDb.OleDbDataReader = mycommand.ExecuteReader()
If myreader.Read() Then
Session("userid") = user_id.Text
Response.Redirect("comm_user.aspx")
ElseIf Not myreader.Read() Then
message.text = "你的输入有误"
message.style("color") = "red"

End If
mycommand.connection.close()
End Sub
Public Sub check_log2()
Dim myconnection As Data.OleDb.OleDbConnection
myconnection = New Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("library.mdb"))
Dim searchcmd As String
searchcmd = "select * from manage where 姓名='" & user_id.Text & "' and 学号='" & password.Text & "'"
Dim mycommand As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand(searchcmd, myconnection)
mycommand.connection.open()
Dim myreader As Data.OleDb.OleDbDataReader = mycommand.ExecuteReader()
If myreader.Read() Then
Session("userid") = user_id.Text
Response.Redirect("admin.aspx")
ElseIf Not myreader.Read() Then
message.text = "你的输入有误"
message.style("color") = "red"

End If
mycommand.connection.close()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
check_log1()
ElseIf RadioButton2.Checked Then
check_log2()
End If
End Sub
End Class
展开
 我来答
ourcolour
2011-12-17 · TA获得超过510个赞
知道小有建树答主
回答量:376
采纳率:0%
帮助的人:256万
展开全部
在使用OleDbConnection的地方用下面代码括起来:

try
'...省略数据库操作
catch oledbex as OleDbException
'..
catch ex as Exception
'..
end try
追问
运行过了么?意思不太明白,代码加在哪里?
追答
楼主需要学习一下VB.Net 的异常捕获。
代码太长了,只写了check_log1()。

Public Sub check_log1()
try
Dim myconnection As Data.OleDb.OleDbConnection
myconnection = New Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("db1.mdb"))
Dim searchcmd As String
searchcmd = "select * from student where 姓名='" & user_id.Text & "' and 学号='" & password.Text & "'"
Dim mycommand As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand(searchcmd, myconnection)
mycommand.connection.open()
Dim myreader As Data.OleDb.OleDbDataReader = mycommand.ExecuteReader()
If myreader.Read() Then
Session("userid") = user_id.Text
Response.Redirect("comm_user.aspx")
ElseIf Not myreader.Read() Then
message.text = "你的输入有误"
message.style("color") = "red"

End If
mycommand.connection.close()
catch oledbex as OleDbException
'..
catch ex as Exception
'..
endtry
End Sub
330167793
2011-12-21
知道答主
回答量:41
采纳率:0%
帮助的人:6.8万
展开全部
Imports System.Data.OleDb
Partial Class Default2
Inherits System.Web.UI.Page

Public Sub check_log1()
Dim myconnection As Data.OleDb.OleDbConnection
myconnection = New Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("db1.mdb"))
Dim searchcmd As String
searchcmd = "select * from studen
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式