数据集中的已删除项目未在数据库中删除 [英] deleted item in dataset not deleted in database

查看:57
本文介绍了数据集中的已删除项目未在数据库中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个功能

 public void RemoveStock(string tickerName) {

    int key = this.getKeyFromtickerName(tickerName);
    foreach (var item in listingDataTable.Where(
        x => x.stock == key).ToList()) {
           listingDataTable.RemoveListingRow(item);
    }
    listingTa.Update(listingDataTable);
}

定义:

listingDataTable = new stockDataSet.ListingDataTable();
listingTa = new stockDataSetTableAdapters.ListingTableAdapter();

数据库类型:SQL Server精简版

Database type: SQL Server Compact Edition

该函数从数据集中删除行,但从数据库中删除行。数据库中所有添加的内容都已存储,但是我不能从数据库中删除。

The function remove rows from the dataset, but not from the database. All additions to the database is stored but I can't delete from the database.

我是否需要做其他事情才能使数据库接受我的更改?

Do I need to do something else to make the database to accept my changes?

最诚挚的问候

Gorgen

Best Regards
Gorgen

推荐答案

原来,我需要在数据库适配器中添加DeleteCommand。 DeleteCommand不是自动生成的,当使用 .RemoveListingRow(item)时,没有发出错误消息,只是没有用。

Turned out that I needed to add an DeleteCommand in my database adapter. The DeleteCommand wasn't automaticly generated and when using .RemoveListingRow(item) no error message was issued, it just didn't work.

在数据源中,选择使用Designer编辑数据集 tableAdaper属性的生成命令,例如

In Data Sources choose "Edit DataSet with Designer" Properties of tableAdaper generate command such as

从清单中删除
WHERE(股票= @ p1)

DELETE FROM Listing WHERE (stock = @p1)

这篇关于数据集中的已删除项目未在数据库中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆