0

Does anyone have an idea on how to update the actual access datbase file? This is my code so far and I think everything is right, but when hit the button to send the information to the actual database file it does not appear in there. Can someone help me with this? The access file I'm talking about is the one outside of the visual basic project itself, but still connected.

Code

Imports System.Data.OleDb

Public Class Form1

Dim provider As String
Dim datafile As String
Dim connString As String
Dim con As New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source=G:\Music Session Database\Music Database.accdb")
Dim ds As New DataSet

Dim dt As New DataTable

Dim da As New OleDbDataAdapter

Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
    Me.Close()
End Sub



Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles btnsubmit1.Click

    Me.Music_DatabaseTableAdapter.Insert(Me.songTitle.Text, Me.songArtist.Text, Me.songAlbum.Text, Me.yearReleased.Text)
    Me.Music_DatabaseTableAdapter.Fill(Me.Music_DatabaseDataSet.Music_Database)


    con.Open()
    MsgBox("Record Added")
    con.Close()
    songTitle.Text = ""
    songArtist.Text = ""
    songAlbum.Text = ""
    yearReleased.Text = ""


End Sub


Private Sub btnsumbit2_Click(sender As Object, e As EventArgs) Handles btnsumbit2.Click

    Me.Play_SessionTableAdapter.Insert(Me.songTitle.Text, Me.songArtist.Text, Me.songAlbum.Text, Me.yearReleased.Text, Me.datePlayed.Text, Me.timePlayed.Text, Me.genre.Text)
    Me.Play_SessionTableAdapter.Fill(Me.Music_DatabaseDataSet.Play_Session)


    con.Open()
    MsgBox("Record Added")
    con.Close()
    songTitle.Text = ""
    songArtist.Text = ""
    songAlbum.Text = ""
    yearReleased.Text = ""
    datePlayed.Text = ""
    timePlayed.Text = ""
    genre.Text = ""



End Sub

Private Sub btnsubmit3_Click(sender As Object, e As EventArgs) Handles btnsubmit3.Click


    Me.Song_Artist_InformationTableAdapter.Insert(Me.songArtist.Text, Me.genre.Text, Me.origin.Text, Me.artistInformation.Text)
    Me.Song_Artist_InformationTableAdapter.Fill(Me.Music_DatabaseDataSet.Song_Artist_Information)

    con.Open()
    MsgBox("Record Added")
    con.Close()
    songArtist.Text = ""
    genre.Text = ""
    origin.Text = ""
    artistInformation.Text = ""


End Sub

Private Sub btnclear_Click(sender As Object, e As EventArgs) Handles btnclear.Click
    songTitle.Clear()
    songArtist.Clear()
    songAlbum.Clear()
    yearReleased.Clear()
    datePlayed.Clear()
    timePlayed.Clear()
    genre.Clear()
    artistInformation.Clear()
End Sub


Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
    Try

    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try

End Sub

Private Sub Music_DatabaseBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles Music_DatabaseBindingNavigatorSaveItem.Click
    Me.Validate()
    Me.Music_DatabaseBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.Music_DatabaseDataSet)

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'Music_DatabaseDataSet.Song_Artist_Information' table. You can move, or remove it, as needed.
    Me.Song_Artist_InformationTableAdapter.Fill(Me.Music_DatabaseDataSet.Song_Artist_Information)
    'TODO: This line of code loads data into the 'Music_DatabaseDataSet.Play_Session' table. You can move, or remove it, as needed.
    Me.Play_SessionTableAdapter.Fill(Me.Music_DatabaseDataSet.Play_Session)
    'TODO: This line of code loads data into the 'Music_DatabaseDataSet.Music_Database' table. You can move, or remove it, as needed.
    Me.Music_DatabaseTableAdapter.Fill(Me.Music_DatabaseDataSet.Music_Database)







End Sub




Private Sub btnupdate1_Click(sender As Object, e As EventArgs) Handles btnupdate1.Click
    Me.Validate()
    con.Open()
    ds.Tables.Add(dt)
    da = New OleDbDataAdapter("Select * from [Music Database]", con)
    Dim cb = New OleDbCommandBuilder(da)
    cb.QuotePrefix = "["
    cb.QuoteSuffix = "]"
    da.Fill(dt)
    Music_DatabaseDataGridView.DataSource = dt.DefaultView
    da.Update(dt)
End Sub

Private Sub btnupdate2_Click(sender As Object, e As EventArgs) Handles btnupdate2.Click
    Me.Validate()
    con.Open()
    ds.Tables.Add(dt)
    da = New OleDbDataAdapter("Select * from [Play Session]", con)
    Dim cb = New OleDbCommandBuilder(da)
    cb.QuotePrefix = "["
    cb.QuoteSuffix = "]"
    da.Fill(dt)
    Play_SessionDataGridView.DataSource = dt.DefaultView

    da.Update(dt)


End Sub

Private Sub btnupdate3_Click(sender As Object, e As EventArgs) Handles btnupdate3.Click
    Me.Validate()
    con.Open()
    ds.Tables.Add(dt)
    da = New OleDbDataAdapter("Select * from [Song Artist Information]", con)
    Dim cb = New OleDbCommandBuilder(da)
    cb.QuotePrefix = "["
    cb.QuoteSuffix = "]"
    da.Fill(dt)
    Song_Artist_InformationDataGridView.DataSource = dt.DefaultView


    da.Update(dt)
End Sub

End Class

6
  • Review stackoverflow.com/questions/12634516/… Commented Apr 16, 2017 at 19:20
  • 1
    Where does the values songTitle, songArtist, songAlbum, yearReleased populate? You initialize in Dim but do not assign values. Shouldn't form values be passed into method? Maybe with sender object or e EventArgs? Sorry not too familiar with VB.Net. Commented Apr 16, 2017 at 19:29
  • @Parfait Can you show me that please? Commented Apr 16, 2017 at 19:44
  • @Parfait Do you someone who is familiar with VB.net? Commented Apr 16, 2017 at 19:52
  • I guess just wait for the VB.Net gurus. But surely, there is a book/tutorial/site you can reference to see how to capture form controls? Google is a programmer's friend sometimes. Commented Apr 16, 2017 at 20:00

1 Answer 1

0

Format of the initialization string does not conform to specification

The connString you create is not valid.

provider = "Microsoft.ACE.OLEDB.12.0"
datafile = "H:\Music Session Database\Music Database.accdb"

connString = provider & datafile

Console.WriteLine(connString)

shows

Microsoft.ACE.OLEDB.12.0H:\Music Session Database\Music Database.accdb

What you want to do is something like

connString = String.Format("Provider={0};Data Source={1}", provider, datafile)

which produces

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\Music Session Database\Music Database.accdb
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.