Hello All
I am having a problem with an application that displays data in datagridview depending on a selection from a combo box.
The problem occurs when I want to write the data back to the database.
I get the following error:
"Update unable to find TableMapping['Product'] or DataTable 'Product'."
Is this because the table in the dataset is filled in a private sub? If so how do I make it public?
Any ideas what is wrong. Code is as follows:
Code:Imports System.Data.OleDb Public Class ProductSpecFrm Dim csProduct As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\VB\signage\signage\product spec.accdb") Dim daProduct As New OleDbDataAdapter("SELECT product.* from product", csProduct) Dim daType As New OleDbDataAdapter("SELECT DISTINCT type FROM product", csProduct) Dim dsProduct As New DataSet Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'Close the Product Spec sub form Me.Close() End Sub Private Sub ProductSpecFrm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Label1.Text = "" 'Maximise the Product Spec sub form on load Me.WindowState = FormWindowState.Maximized 'Load the Datagrid with from dataset daProduct.Fill(dsProduct, "Product") dgProduct.DataSource = dsProduct.Tables("Product") 'Hide Columns dgProduct.Columns("ProductID").Visible = False 'Change Row Colours dgProduct.RowsDefaultCellStyle.BackColor = Color.LightBlue dgProduct.AlternatingRowsDefaultCellStyle.BackColor = Color.White 'Load the Type combobox dsProduct.Tables.Clear() daProduct.Fill(dsProduct, "Type") With ComboBox1 .DataSource = dsProduct.Tables("Type") .DisplayMember = "Type" .ValueMember = "Type" .SelectedIndex = 0 End With End Sub Private Sub dgProduct_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgProduct.CellContentClick End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click 'Filter Datagrid by Type combobox dsProduct.Tables.Clear() Dim ComboVal As String = ComboBox1.Text Dim daTypeFilter As New OleDbDataAdapter("SELECT product.* FROM product WHERE type='" & ComboVal & "'", csProduct) daTypeFilter.Fill(dsProduct, "Type Filtered") dgProduct.DataSource = dsProduct.Tables("Type Filtered") Label1.Text = "Filtered by: " & ComboVal End Sub Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged End Sub Private Sub CopyBtn_Click(sender As System.Object, e As System.EventArgs) Handles CopyBtn.Click 'Copy the current cells contents to the clipboard Dim CurrentRowIndex As Integer = dgProduct.CurrentRow.Index Dim ToClipBoard As String ToClipBoard = dgProduct.Item(2, CurrentRowIndex).Value Clipboard.SetDataObject(ToClipBoard, True) End Sub Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click 'Update the data back to the database daProduct.Update(dsProduct, "Product") MsgBox("Data updated") End Sub End Class


Reply With Quote
Bookmarks