Working with dataset vb.net
Using Visual Studio 2010
I am trying to using windows form drag and drop by datasource .
the grid generate automatically and with navigation bar with few controls like add, save , delete.
But its not work on main table , meanS When I want to add new , it show saved but its not saved in actual datatable. please help to update, insert , and delete .
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 Syst开发者_开发百科em.EventArgs) Handles TransBindingNavigatorSaveItem.Click
Me.Validate()
Me.TransBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Agents_DataSet)
End Sub
since Access doesn't support LINQ you have to type the statements on your own i think.
This is a snippet of an old Project where i wrote my own Querys to 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
EDIT and here the OleDb connection:
''' <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
精彩评论