我想將一些數據庫記錄鏈接到文本框和一個帶有Visual Basic和OLEDB的列表框,但是當我調試程序時,即使數據庫位於bin/debug
文件夾中,程序也不會識別它。OLEDB連接是未處理的錯誤
下面是代碼:
Imports System.Data.OleDb
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = Hospital.mdb"
Dim dtPatientsIDs As New DataTable
Dim daPatientIDs As New OleDbDataAdapter _
("Select [Patient ID] From Patients", ConnectString)
daPatientIDs.Fill(dtPatientsIDs)
lstPatientIDs.DataSource = dtPatientsIDs
lstPatientIDs.DisplayMember = "Patient ID"
OleDbDataAdapter1.Fill(DsPatientsAndWards1)
txtWardName.DataBindings.Add("Text", DsPatientsAndWards1, _
"Patients.Ward Name")
txtWardType.DataBindings.Add("Text", DsPatientsAndWards1, _
"Patients.Ward Type")
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
BindingContext(DsPatientsAndWards1, "Patients").Position = _
BindingContext(DsPatientsAndWards1, "Patients").Position - 1
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
BindingContext(DsPatientsAndWards1, "Patients").Position = _
BindingContext(DsPatientsAndWards1, "Patients").Position + 1
End Sub
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
Dim index As Short
index = lstPatientIDs.SelectedIndex
BindingContext(DsPatientsAndWards1, "Patients").Position = index
End Sub
End Class
here is the error and its location
沒有創建Connection對象......這可能是異常消息的一部分。數據庫可能會更好地保存到用戶文件夾......部署時不會是VS BIN文件夾 – Plutonix
除非您告訴我們錯誤是什麼以及它在哪裏,否則我們不能幫助您。 – Steve
此異常還具有帶有更有意義的消息的InnerException屬性。請添加 – Steve