Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > TableAdapter.Fill Problem - No mapping from DBType to SqlDBType
 

TableAdapter.Fill Problem - No mapping from DBType to SqlDBType

Hi Everyone,

My application keeps throwing an error when I run a .Fill command to a dataset. The weird thing is, it was working before, but it seems suddenly I keep getting this new error. I don't think I changed anything to cause it, but I am relatively new to the TableAdaptor arena so it is probably a simple fix.

I try to run the following command:

Me.TblExpenseRecordsTableAdapter.Fill(Me.PCMDataSet.tblExpenseRecords)

It highlights the line: Me.InitCommandCollection() and says ArgumentException was unhandled. No mapping exists from DbType Object to a known SqlDbType.

The weird (or perhaps not) thing is that if I put a break point on the me._commandCollection Is Nothing line, when it runs through the code, when it gets to this logic test, the Me._commandCollection IS nothing. However, once it has errored on the Me.InitCommandCollection and I hover the mouse over Me._commandCollection, it is suddenly there!!

To date I have worked around this error by using a Try Catch Finally End Try, with both the Try and Finally areas running the code:
Me.TblExpenseRecordsTableAdapter.Fill(Me.PCMDataSet.tblExpenseRecords)

This works (because of the second time around at the finally code), but means that i need to put try around every fill i use.

If someone could please assist I would be appreciative.

Thanks

  • Moved byMartin Xie - MSFTMSFTMonday, August 03, 2009 3:54 AMMove it for better support. (From:Visual Basic Express Edition)
  •  
notquiteanexpert  Saturday, August 01, 2009 9:40 AM
Hi Aland,

I was just fiddling around and got it working......

The steps I took were as follows:

1. In the Data Sources, click 'Configure Dataset with Wizard'.
2. Uncheck the tblExpenseRecords from the selected tables. Then click Finish. This removed the entire table from my application.
3. Doing the same thing, add back the table.
4. Recreate all my user defined sql queries in the dataset designer.

And now it works!!

If you have any ideas as to why this happened, or in particular, what the particular error means, I would be greatly appreciative in case it happens again!!

Thanks.
notquiteanexpert  Tuesday, August 04, 2009 9:45 AM

Hi notquiteanexpert ,

Could you please post some code snippets or provide the steps for me to reproduce the problem? You need to check the value of the parameters used to build the command. Some special values, such as null, can lead to this error.

If you want to avoid handling the error too many times. You can create your own DataAdapter and override the Fill method and write the “Try Catch�code there. This is a code snippet:

Public Class MyTableAdapter 
    Inherits DataAdapter 
    Public Overloads Overrides Function Fill(ByVal dataSet As DataSet) As Integer 
        Try 
            Return MyBase.Fill(dataSet) 
        Catch 
            'Handle error here. 
        Finally 
            'Do something to finish the error handling. 
        End Try 
        
        Return 0 
    End Function 
End Class


Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Tuesday, August 04, 2009 8:55 AM
Hi Aland,

Thanks for that. To be honest, I don't really want to create my own tableadapters, but just want to understand what is going on here.

Essentially, I am trying to load a form which contains various combo boxes and date ranges, which requires data from 4 particular tables.As such, on loading the form, the following code is meant to populate the dataset. This works for 3 of the tables, just not the tblExpenseRecords table.

If I comment out the tblExpenseRecord row, the code works absolutely fine (i.e. table adaptors don't throw errors), so there is something I'm doing wrong with the expense records table. I added the tableadaptor etc in the exactly same manner (by dragging the table from the datasource onto the form etc).

The code is as follows:

Me.TblIncomeRecordsTableAdapter.Fill(Me.PCMDataSet.tblIncomeRecords)

Me.TblExpenseRecordsTableAdapter.Fill(Me.PCMDataSet.tblExpenseRecords)

Me.TblIncomeCategoriesTableAdapter.Fill(Me.PCMDataSet.tblIncomeCategories)

Me.TblExpenseCategoriesTableAdapter.Fill(Me.PCMDataSet.tblExpenseCategories)


The error takes me to the dataset designer code (i.e. PCMDataSet.Designer.vb tab):

<Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _

Protected ReadOnly Property CommandCollection() As Global.System.Data.SqlServerCe.SqlCeCommand()

Get

If (Me._commandCollection Is Nothing) Then

Me.InitCommandCollection

End If

Return Me._commandCollection

End Get

End Property


And shows the error on Me.InitCommandCollection.

Hope this helps highlight the error. I'm struggling to understand why the other tables dont have the same problem......

If it helps diagnose the problem, this same problem occurs on other forms with only this table....?

Thanks so much :-).










notquiteanexpert  Tuesday, August 04, 2009 9:33 AM
Hi Aland,

I was just fiddling around and got it working......

The steps I took were as follows:

1. In the Data Sources, click 'Configure Dataset with Wizard'.
2. Uncheck the tblExpenseRecords from the selected tables. Then click Finish. This removed the entire table from my application.
3. Doing the same thing, add back the table.
4. Recreate all my user defined sql queries in the dataset designer.

And now it works!!

If you have any ideas as to why this happened, or in particular, what the particular error means, I would be greatly appreciative in case it happens again!!

Thanks.
notquiteanexpert  Tuesday, August 04, 2009 9:45 AM

Hi notquiteanexpert,

Thanks for your reply. From my experience, you might change the structure of the expense records table in the database. This would lead to the type inconsistence between the table in database and the code in your project. When you use the designer to rebuild the code, the inconsistence is removed.

Best regards,
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Tuesday, August 04, 2009 9:56 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGrid/Gridview
• Retrieving Property Values with Reflection
• BindingSource, DatagridView and Regional Settings
• Alternate Row Color for entire grid
• Free values in ComboBox in DataGridView
• Dataset
• Dynamic Property Grid Enum
• Two Windows Application, single Database.
• DataBinding Issues using IEditableObject
• Set SelectedIndex for a DataGridViewComboBoxColumn