简体   繁体   English

我如何从vb.net添加到Access数据库

[英]How can i add into access database from vb.net

Am still learning VB and database but I have a little problem. 我还在学习VB和数据库,但是我有一个小问题。 My codes works but when I try to look into the database I don't find all what are been saved, how do I rectify it? 我的代码有效,但是当我尝试查看数据库时,找不到所有已保存的内容,该如何纠正? and also the edit and delete. 以及编辑和删除。 thanks 谢谢

Here is my code: 这是我的代码:

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

You probably have your MDB (ACCDB) file included in your project files. 您的项目文件中可能包含MDB(ACCDB)文件。 If you check the properties associated with this project file you will find one named Copy to Output Directory. 如果您检查与此项目文件关联的属性,则会找到一个名为“复制到输出目录”的副本。 Set this to Copy Always. 将此设置为始终复制。

Also your connection string contains the shortcut Data Source = "|DataDirectory|\\yourdb.mdb" 另外,您的连接字符串还包含快捷方式Data Source =“ | DataDirectory | \\ yourdb.mdb”

If this scenario is correct, then you start your application and the MDB / ACCDB file is copied from the original location to the BIN\\DEBUG directory. 如果这种情况是正确的,则启动您的应用程序,然后将MDB / ACCDB文件从原始位置复制到BIN \\ DEBUG目录。 You insert your data there without error. 您将数据正确插入那里。 When you stop the debug session to fix errors or other problems you restart your application and the fresh copy (but empty) of your db is copied again in the output directory. 当您停止调试会话以修复错误或其他问题时,请重新启动应用程序,然后将db的新副本(但为空)再次复制到输出目录中。

To fix this, set the property to Copy Never or change your connection string to point to a fixed location. 要解决此问题,请将属性设置为“从不复制”,或将连接字符串更改为指向固定位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM