这是我关于stackoverflow的第一篇文章,所以请跟我一起。我正在尝试使用VB.NET更新访问数据库。使用以下系列视频(从这一个开始),我们已经能够正确使用我们的表单将新数据保存到访问数据库中。 https://www.youtube.com/results?search_query=vb.net+ms+access+database+tutorial+1+%23+add+new+remove+save+data+in+database+using+vb.net
然而,当我们在打开访问权限后再次启动表单以确保更新已经发生(他们总是这样做)时,我们没有任何更改。当我们再次打开访问时,我们在访问数据库中显示的更改消失了,访问数据库又回到了原始状态(我们首先将它链接到visual studio时的状态)。
以下是我们到目前为止的代码,感谢您提供给我们的任何帮助!
感谢。
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Sheet1BindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Sheet1BindingNavigatorSaveItem.Click
Me.Validate()
Me.Sheet1BindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(MIS275_Small_BusinessDataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MIS275_Small_BusinessDataSet.Sheet1' table. You can move, or remove it, as needed.
Timer1.Start()
Me.Sheet1TableAdapter.Fill(MIS275_Small_BusinessDataSet.Sheet1)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Sheet1BindingSource.AddNew()
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click
Try
Sheet1BindingSource.EndEdit()
Sheet1TableAdapter.Update(MIS275_Small_BusinessDataSet.Sheet1)
MessageBox.Show("Data Saved")
Catch ex As Exception
MessageBox.Show("Error")
End Try
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim count As Integer
count = Sheet1BindingSource.Count
End Sub
End Class