0
我有這段代碼,我寫了一個數據庫中是否存在記錄。當找到記錄時它運作良好。如果不是,則會引發錯誤。我想這個錯誤會被記錄在一個消息框中,表示「找不到記錄」。如何捕獲oledbdatareader錯誤
Dim findprinc As String = TextBox1.Text.Substring(0, 16)
MsgBox(findprinc)
sql = "Select RealID from Dets where ID like '%" & findprinc & "%'"
MsgBox(sql)
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Persist Security Info=false; Data Source=..\new.mdb")
conn.Open()
Dim cmd As New OleDbCommand(sql, conn)
Dim numeri As OleDbDataReader = cmd.ExecuteReader
numeri.Read()
之前,你'.Read'檢查'numeri.HasRows' – Plutonix