Very very new to visual basic.net (first day actually) but struggling already with the basics. I am attempting to create a single form application taking data from an existing MS Access database using SQL query. All works great, I can fill the dataset, seek, sort and display all my data and make changes to records within the dataset but when I try to write the values back to the database using the command

objOwnerDA.Update(objDataSet, "Owners")

I get the error:

Update unable to find TableMapping or DataTable 'Owners'.

Assuming the problem was with my coding I downloaded source code accompanying another of my tutorial books but that gives me the same error when I try to update the database. It is reassuring that it is not my coding but extremely frustrating none the less.

Any suggestions (keep them simple please) greatly appreciated.

Recommended Answers

All 3 Replies

It will all depend on what the rest of your coding looks like. For example if I retrieve data from a table named Owners, it doesnt mean i put it in a dataset or datatable in the program thats named the same. I'm assuming this is the problem here.

Also I dont know what your update statement looks like or if you even created and assigned on you your dataadapter.

Cutting out the seek sort and display stuff here are the key chunks of code :

Public Class Form1
    Dim inc As Integer
    Dim con As New OleDb.OleDbConnection
    Dim da As OleDb.OleDbDataAdapter
    Dim cb As New OleDb.OleDbCommandBuilder(da)
    Dim ds As New DataSet
    Dim dbProvider As String
    Dim dbSource As String
    Dim sql As String
    Dim MaxRows As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source= d:/pricing/pricingV21.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "SELECT Message.messageID, Message.quoteRef, Message.MessageTitle, Message.MessageNotes, Message.MessageDate, Message.MessageReviewDate, Message.MessageCompleteDate, Message.MessageType, Message.MessageTrigger, Quote.QuoteAddress, Quote.QuoteClient, Quote.QuotePhone, [messagereviewdate]-Now() AS DateDiff FROM Message INNER JOIN Quote ON Message.quoteRef = Quote.QuoteID WHERE(((Message.MessageDate) <= Now()) And ((Message.MessageCompleteDate) Is Null))ORDER BY Message.MessageReviewDate"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "messages")
        MaxRows = ds.Tables("messages").Rows.Count
        inc = 0
        msgProgress.Minimum = 0
        msgProgress.Maximum = MaxRows
        NavigateRecords()

    End Sub

after all the action

Private Sub msgHappy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msgHappy.Click
        ds.Tables("messages").Rows(inc).Item("messageCompleteDate") = Now()
        da.Update(ds, "messsages")
     End Sub

If I am missing something obvious be gentle with me!

Ok you did explicity give it a table name during the fill. However you didnt explicity asign the comandbuilder commands that you want to use after assigning the select command to the dataadapter. Take a look at my changes below.

Also Im assuming MessageId is a primarykey or unique identifier in the table; which is needed by the command builder.

Cutting out the seek sort and display stuff here are the key chunks of code :

Public Class Form1
    Dim inc As Integer
    Dim con As New OleDb.OleDbConnection
    Dim da As OleDb.OleDbDataAdapter
    Dim cb As OleDb.OleDbCommandBuilder = Nothing
    Dim ds As New DataSet
    Dim dbProvider As String
    Dim dbSource As String
    Dim sql As String
    Dim MaxRows As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source= d:/pricing/pricingV21.mdb"
        con.ConnectionString = dbProvider & dbSource
        con.Open()
        sql = "SELECT Message.messageID, Message.quoteRef, Message.MessageTitle, Message.MessageNotes, Message.MessageDate, Message.MessageReviewDate, Message.MessageCompleteDate, Message.MessageType, Message.MessageTrigger, Quote.QuoteAddress, Quote.QuoteClient, Quote.QuotePhone, [messagereviewdate]-Now() AS DateDiff FROM Message INNER JOIN Quote ON Message.quoteRef = Quote.QuoteID WHERE(((Message.MessageDate) <= Now()) And ((Message.MessageCompleteDate) Is Null))ORDER BY Message.MessageReviewDate"
        da = New OleDb.OleDbDataAdapter(sql, con)

        cb = New OleDb.OleDbCommandBuilder (da)        
        da.InsertCommand = cb.GetInsertCommand()
        da.UpdateCommand = cb.GetUpdateCommand()
        da.DeleteCommand = cb.GetDeleteCommand() 

       da.Fill(ds, "messages")
        MaxRows = ds.Tables("messages").Rows.Count
        inc = 0
        msgProgress.Minimum = 0
        msgProgress.Maximum = MaxRows
        NavigateRecords()

    End Sub

after all the action

Private Sub msgHappy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles msgHappy.Click
        ds.Tables("messages").Rows(inc).Item("messageCompleteDate") = Now()
        da.Update(ds, "messsages")
     End Sub

If I am missing something obvious be gentle with me!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.