扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠编译 来源:天极开发 2007年11月9日
关键字:
Public Class DatabaseUnavailableException Inherits DatabaseException Public Sub New(ByVal ex As Exception) MyBase.New("The database is not available.", ex) End Sub End Class |
Private Sub ConnectDB(ByVal database As String, _ ByRef cn As OleDbConnection) cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; _ Data Source=" & _ """" & database & """" Try cn.Open() Catch ex As Exception Throw New DatabaseUnavailableException(ex) End Try End Sub |
Private Sub GetCustomerData(ByVal cn As OleDbConnection, _ ByVal customerID As Long) Dim cmd As New OleDbCommand Dim reader As OleDbDataReader cmd.Connection = cn cmd.CommandText = "SELECT * FROM CUSTOMER WHERE ID = " _ & customerID reader = cmd.ExecuteReader If reader.HasRows Then reader.Read() m_id = reader.Item("ID") m_firstname = reader.Item("Firstname") m_lastName = reader.Item("Lastname") m_street = reader.Item("Street") m_city = reader.Item("City") m_state = reader.Item("State") m_zipCode = reader.Item("Zip") Else Throw New CustomerNotFoundException(customerID) End If End Sub |
图1.成功的查询 图2.CustomerNotFoundException 图3.DatabaseUnavailableException |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者