在瀏覽網頁找到答案後,我看到了這個網站,它解釋了VB6中的錯誤處理。
我終於可以繼續前進。下面的代碼:
On Error GoTo err_CmdAdd_Click
con.Open _
"Provider = sqloledb;" & _
"Data Source=server;" & _
"Initial Catalog=database;" & _
"User ID=username;" & _
"Password=password;"
If img_edit.BorderStyle = 1 Then
Set rs = con.Execute("insert into a_owner values('" & txt_unit.Text & "', " _
& " '" & txt_tower.Text & "' )")
MsgBox "Record added successfully...", vbInformation
ado1.Refresh
exit_err_CmdAdd_Click:
Exit Sub
err_CmdAdd_Click:
MsgBox "Duplicate Record!", vbCritical, "Duplicate"
txt_unit.Text = ""
txt_unit.SetFocus
End If
你爲什麼不查詢數據庫並獲取價值。那就比較一下吧?或者,您可以通過將文本框的值傳遞給查詢本身來進行比較! –