This is my first attempt at working with .NET and a database.
I am trying to add records to a table but nothing is being added. I have stripped it down to just the basic code below.
No errors are generated but nothing is added to the table.
Imports System.Data
'Imports System.Data.OleDb
Class Form1
Dim dbProvider As String
Dim dbSource As String
Dim dbPathAndFilename As String
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" ' MDB
'dbProvider = "PROVIDER=Microsoft.Ace.OLEDB.12.0;" 'ACCDB
dbSource = "Data Source="
LoadData()
End Sub
Sub LoadData()
'Connect to db
'You could store the db path in the Settings of the App.
'dbPathAndFilename = My.Settings.dbPath
dbPathAndFilename = "C:\temp\VB\DBTest\Test.mdb"
con.ConnectionString = dbProvider & dbSource & dbPathAndFilename
con.Open()
sql = "INSERT INTO Table1(Field1) VALUES('Field1');"
da = New OleDb.OleDbDataAdapter(sql, con)
con.Close()
End Sub
End Class