Results 1 to 5 of 5

Thread: [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    21

    [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'

    Hi

    I have a DataGridView,I want the user to Add,Edit and delete rows from the table
    My code is:
    Code:
    Private cn As New SqlConnection("Data Source=localhost;Initial Catalog=NorthWind;Integrated Security=True")
        Private da As New SqlDataAdapter()
        Private dt As New DataSet()
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim cm As New SqlCommand("SELECT CustomerID,CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers", cn)
            da.SelectCommand = cm
    
            Dim cmbuilder As New SqlCommandBuilder(da)
            'auto generate the UpdateCommand,InsertCommand and DeleteCommand 
            da.Fill(dt, "Customer")
    
            Me.DataGridView1.DataSource = dt
            Me.DataGridView1.DataMember = "Customer"
        End Sub
        
        
        Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
            Me.DataGridView1.BindingContext(dt).EndCurrentEdit()
            Me.da.Update(dt)
        End Sub
    I have 2 questions:
    When I edit a row and then press Save the following message appears:
    Update unable to find TableMapping['Table'] or DataTable 'Table'.

    Also I don't want to display CustomerID in my DataGridView.
    how can I make it invisible(I want to include CustomerID in my select statement but not display it in the datagridview)

    Any help?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'

    First up, isn't "dt" a bit of a dodgy name for a variable of type DataSet? Wouldn't "dt" be more appropriate for a DataTable, and "ds" be better for a DataSet?

    As for the issue, here's how you're filling the DataTable:
    Code:
    da.Fill(dt, "Customer")
    Do you see anything missing when you save it?
    Code:
    Me.da.Update(dt)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'

    Quote Originally Posted by cuterita7
    Also I don't want to display CustomerID in my DataGridView.
    how can I make it invisible(I want to include CustomerID in my select statement but not display it in the datagridview)

    Any help?
    You've got two choices. You can add all the other columns to the grid in the designer and set the AutoGenerateColumns property to False. Alternatively, and more easily, you can just get the grid column that's bound to the CustomerID and either remove it or else set it's Visible property to False.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2008
    Posts
    21

    Re: [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'

    thanks
    I need one more question

    I have added to my DataGridView a datagridviewcombobox column

    Code:
    Dim source As New DataGridViewComboBoxColumn
            source.DataSource = ds.Tables("Source")
            source.DataPropertyName = "SourceID"
            source.DisplayMember = "Source"
            source.ValueMember = "SourceID"
    
            Me.DataGridView1.Columns.Add(source)
    I want to give the user the ability to not select any value of the source datagridviewcomboboxcolumn so i was thinking to insert "--Select--" at index 0 of the datagridviewcomboboxcolumn but i got the following message
    Items collection cannot be modified when the DataSource property is set.

    any help?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'

    If you want the user to make no selection then that's exactly what you should do. You just assign DBNull.Value to the cell's Value property, which will correspond to a no selection in the combo box. You can handle an appropriate key combination in that cell, like Ctrl+0 or Ctrl+Delete.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width