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 展开
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 展开
2个回答
展开全部
在使用OleDbConnection的地方用下面代码括起来:
try
'...省略数据库操作
catch oledbex as OleDbException
'..
catch ex as Exception
'..
end try
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
展开全部
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询