[英]How can i add into access database from vb.net
我還在學習VB和數據庫,但是我有一個小問題。 我的代碼有效,但是當我嘗試查看數據庫時,找不到所有已保存的內容,該如何糾正? 以及編輯和刪除。 謝謝
這是我的代碼:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
'TODO: This line of code loads data into the 'ItemsDataSet.Items' table. You can move, or remove it, as needed.
Me.ItemsTableAdapter.Fill(Me.ItemsDataSet.Items)
End Sub
Private Sub ItemsDataSetBindingSource_CurrentChanged(sender As Object, e As EventArgs)
End Sub
Private Sub btnedit_Click(sender As Object, e As EventArgs) Handles btnedit.Click
ItemsBindingSource.EndEdit()
ItemsTableAdapter.Update(ItemsDataSet.Items)
MsgBox("Saved")
End Sub
Private Sub btadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click
ItemsBindingSource.AddNew()
MsgBox("Added Successfully")
End Sub
Private Sub btndelete_Click(sender As Object, e As EventArgs) Handles btndelete.Click
ItemsBindingSource.RemoveCurrent()
MsgBox("Item Deleted")
End Sub
Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
Close()
End Sub
Private Sub btnprevious_Click(sender As Object, e As EventArgs) Handles btnprevious.Click
ItemsBindingSource.MovePrevious()
End Sub
Private Sub btnnext_Click(sender As Object, e As EventArgs) Handles btnnext.Click
ItemsBindingSource.MoveNext()
End Sub
End Class
您的項目文件中可能包含MDB(ACCDB)文件。 如果您檢查與此項目文件關聯的屬性,則會找到一個名為“復制到輸出目錄”的副本。 將此設置為始終復制。
另外,您的連接字符串還包含快捷方式Data Source =“ | DataDirectory | \\ yourdb.mdb”
如果這種情況是正確的,則啟動您的應用程序,然后將MDB / ACCDB文件從原始位置復制到BIN \\ DEBUG目錄。 您將數據正確插入那里。 當您停止調試會話以修復錯誤或其他問題時,請重新啟動應用程序,然后將db的新副本(但為空)再次復制到輸出目錄中。
要解決此問題,請將屬性設置為“從不復制”,或將連接字符串更改為指向固定位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.