使用Visual Studio 2010
我正在尝试使用数据源拖放窗体。
网格自动生成,导航栏只有少量控件,如添加,保存,删除。
但它在主表上不起作用,意思是当我想添加新内容时,它显示已保存,但未保存在实际数据表中。请帮助更新,插入和删除。
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Agents_DataSet.trans' table. You can move, or remove it, as needed.
Me.TransTableAdapter.Fill(Me.Agents_DataSet.trans)
End Sub
Private Sub TransBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransBindingNavigatorSaveItem.Click
Me.Validate()
Me.TransBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Agents_DataSet)
End Sub
答案 0 :(得分:0)
由于Access不支持LINQ,你必须自己输入语句。
这是一个旧项目的片段,我在那里写了我自己的Querys到DB。
''' <summary>
''' ExecuteQuery - Execute the query and returns true the excecution was successful
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function ExecuteQuery(ByVal sQuery As String) As Boolean
Dim cConnection As OleDb.OleDbConnection = ConnectToAccess()
Try
Dim cmd As New OleDb.OleDbCommand(sQuery, cConnection)
cmd.ExecuteNonQuery()
Return (True)
Catch ex As Exception
Return False
Finally
If cConnection IsNot Nothing Then cConnection.Close()
End Try
End Function
编辑,这里是OleDb连接:
''' <summary>
''' ConnectToAccess - Etablish conncetion to the selected access Database
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function ConnectToAccess() As OleDb.OleDbConnection
Try
Dim myOleDbConnection As New OleDb.OleDbConnection
myOleDbConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=access.mdb;Jet OLEDB:Database Password=yourPassword;")
myOleDbConnection.Open()
Return myOleDbConnection
Catch ex As Exception
MsgBox("Couldnt etablish the connection to Access. ", ex)
Return Nothing
End Try
End Function