|
-
Nov 24th, 2008, 03:55 AM
#1
Thread Starter
Junior Member
[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?
-
Nov 24th, 2008, 04:02 AM
#2
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?
-
Nov 24th, 2008, 04:05 AM
#3
Re: [2008] Update unable to find TableMapping['Table'] or DataTable 'Table'
 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.
-
Nov 24th, 2008, 05:26 AM
#4
Thread Starter
Junior Member
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?
-
Nov 24th, 2008, 06:44 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|