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

前端 未结 3 1246
渐次进展
渐次进展 2021-01-17 23:52

This code snippet is throwing an error:

Update unable to find TableMapping[\'Table\'] or DataTable \'Table\'.) on adapter.Update(ds); line

3条回答
  •  一向
    一向 (楼主)
    2021-01-18 00:17

    It's because .NET cannot assume that the table name in the DataSet/DataTable is identical to the database table. Thus .NET warns you about it.

    To solve it you need to add a mapping to the DataAdapter:

    da.TableMappings.Add("TableNameInDb", "TableNameInTheDataSet");
    

    However, even if you have specified a name in the DataSet or the DataSource it still doesn't work, since the adapter seems to forget the name.

    I only got it working by using:

    da.TableMappings.Add("Table", "TableNameInDb");
    

提交回复
热议问题