c# - TableAdapter.update方法,到哪里去了?

标签 c# .net data-binding listbox tableadapter

我用你的标准智能控制东西制作了一个列表框,并将其连接到数据库。它获取我通过查询生成器预先生成的数据,所以当我这样做时:

this.calibrate_swipesTableAdapter.Fill(this.xperdex_crandallDataSet.calibrate_swipes);

我得到一个包含我的数据的列表框。

然后,当我向其中添加一大块数据时,通过以下方式:

toadd["card_number"] = card_number;
this.xperdex_crandallDataSet.Tables["calibrate_swipes"].Rows.Add(toadd);

它也有效。效果很好。现在,当我关闭时,我会丢失所有信息。更新我的适配器和 AcceptChanges,对吗?

没那么快。当我打电话时

this.calibrate_swipesTableAdapter.Update(this.xperdex_crandallDataSet.calibrate_swipes);

我得到“不包含‘更新’的定义”。

什么给了?我不明白为什么执行填充的同一件事没有更新方法。

最佳答案

您可能想看看 TableAdapter Overview其中指出:

If there is enough information in the main query, the InsertCommand, UpdateCommand, and DeleteCommand commands are created by default when the TableAdapter is generated. If the TableAdapter's main query is more than a single table SELECT statement, it is possible the designer will not be able to generate the InsertCommand, UpdateCommand, and DeleteCommand. If these commands are not generated, you may receive an error when executing the TableAdapter.Update method.

你有两个选择:

  • 更改您的主要查询
  • 更改更新命令。

要更改 UpdateCommand,请找出为 TableAdapter 生成的类的名称。代码应如下所示:


SqlCommand yourUpdateCommand = new SqlCommand("UPDATE...", connection);
this.calibrate_swipesTableAdapter.Adapter.UpdateCommand = yourUpdateCommand;

更新:

正如评论者所说,还有其他情况可能无法生成命令。 查看评论。

关于c# - TableAdapter.update方法,到哪里去了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1396675/

相关文章:

.net - VS 2010 IDE 2GB 限制

c# - 与 WPF 的数据绑定(bind)

c# - 使用 itextSharp 阅读数学方程式

c# - 使用多线程在 .NET 2.0 中并行处理记录

c# - 如何使用 Moq 测试 ServiceStack 服务

c# - 读/写字符串二进制数据 - BinaryReader

.net - 与 applicationSettings 等效的 appSettings 文件属性

c# - 当传入参数的值来自 Function 时,没有记录返回

WPF,基于触发器更改绑定(bind),可能吗?

c# - 单击时动态创建的控件消失