Hye ...我目前正在使用vb.net做最後一年的項目,並且出現此錯誤。我試着'來解決這個錯誤,但仍然不成功。我在我的項目中使用ms訪問數據庫。我嘗試在'dt'語句之前放置con.Open(),在'cboProduct.Select'之後放置con.Close(),但結果相同。真的很感謝你的幫助。謝謝:)連接未關閉連接當前狀態已打開
'GLOBAL DECLARATIONS
Dim conString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Acer User\Documents\MAKLUMAT IVENTORI.accdb"
Dim con As OleDbConnection = New OleDbConnection(conString)
Dim adapter As New OleDbDataAdapter
Dim cmd As New OleDbCommand
Dim dt As New DataTable
Dim ds As New DataSet
Private Sub RefreshData()
dt = New DataTable
ds = New DataSet
ds.Tables.Add(dt)
adapter = New OleDbDataAdapter("Select * FROM product WHERE lab_kod='66'", con)
adapter.Fill(dt)
DataGridView1.DataSource = dt.DefaultView
labelID.Text = getAutoID()
lblLabCode.Text = "66"
cboProduct.Select()
Dim v_SQL As String = "SELECT * FROM kategori_product"
cmd = New OleDbCommand(v_SQL, con)
con.Open()
Dim v_dataReader As OleDbDataReader = cmd.ExecuteReader()
Dim v_dataTable As New DataTable
v_dataTable.Columns.Add("product_kod", Type.GetType("System.String"))
If v_dataReader.HasRows Then
While v_dataReader.Read
v_dataTable.Rows.Add(v_dataReader.GetString(0))
End While
cboProduct.DataSource = v_dataTable
End If
cboProduct.DisplayMember = "product_kod"
cboProduct.ValueMember = "product_kod"
v_dataReader.Close()
con.Close()
End Sub
'getAutoID()'做了什麼?它是否使用相同的全局連接?它用於自動編號的 – Crowcoder
。所以用戶不需要將號碼放入ID標籤。對。使用相同的全局連接.. –
然後我懷疑這是打開連接。如果是,請在退出'getAutoID'之前關閉它。 – Crowcoder