数据集中已删除的项目未在数据库中删除
大家好
我有一个函数
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 Compact Edition
该函数从数据集中删除行,但不从数据库中删除行。所有添加到数据库的内容都会被存储,但我无法从数据库中删除。
我需要做其他事情来使数据库接受我的更改吗?
最好的问候
戈尔根
Hello everone
I have a function
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);
}
Definitions:
listingDataTable = new stockDataSet.ListingDataTable();
listingTa = new stockDataSetTableAdapters.ListingTableAdapter();
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?
Best Regards
Gorgen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
我认为这实际上会标记要删除的行。
Try this instead:
I think this will actually mark the row for deletion.
结果我需要在我的数据库适配器中添加一个DeleteCommand。 DeleteCommand 不是自动生成的,并且在使用
.RemoveListingRow(item)
时没有发出错误消息,它只是不起作用。在数据源中选择“使用设计器编辑数据集”tableAdaper 的属性生成命令,例如
DELETE FROM Listing
哪里(股票 = @p1)
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.In Data Sources choose "Edit DataSet with Designer" Properties of tableAdaper generate command such as
DELETE FROM Listing
WHERE (stock = @p1)