简体   繁体   English

.net将文本框绑定到数据集。 无法通过调用dataAdapter.update()更新SQL值

[英].net binding a textbox to a dataset. Sql value not updated by calling dataAdapter.update()

I'm sure this is trivial. 我敢肯定这很简单。 But i can't work out why my database isn't getting updated when i've got similar setups elsewhere which seem to be working correctly. 但是我无法弄清楚为什么在其他地方似乎也能正常工作的情况下我的数据库没有得到更新。

I have a typed dataset called DSEditObject and an instance of that on my form called DsEditObject1. 我有一个名为DSEditObject的类型化数据集,并且在我的表单上名为DsEditObject1的实例。 This dataset has a table in it called 'Object'. 该数据集中有一个名为“对象”的表。

I have a textbox whose databinding text property is: ObjectBindingSource - objectName 我有一个文本框,其数据绑定文本属性为:ObjectBindingSource-objectName

This 'ObjectBindingSource' has a datasource property of: DsEditObject1 and a datamember property of 'Object'. 此“ ObjectBindingSource”的数据源属性为:DsEditObject1,而datamember属性为“ Object”。

When i load the form i fill the dataset using a dataadapter configured at runtime. 当我加载表单时,我使用在运行时配置的dataadapter填充数据集。 The textbox.text property gets set to the column data from my database that i expect. textbox.text属性被设置为我期望的数据库中的列数据。

I handled the click from a save button and call 我处理了保存按钮上的点击,然后致电

SqlDataAdapter1.Update(DsEditObject1, "Object")

I have used the command window and checked that the value in the dataset has been changed to the textbox input before the update command gets called: 我使用了命令窗口,并在调用update命令之前检查了数据集中的值是否已更改为文本框输入:

UPDATE [Object] SET [objectName] = @objectName WHERE (([objectID] = @Original_objectID)) 更新[Object] SET [objectName] = @objectName在哪里(([[objectID] = @Original_objectID))

But for some reason my database isn't getting updated and I am receiving no errors 但是由于某种原因,我的数据库没有更新,并且没有收到任何错误

Edit: 编辑:

i'd forgotten to call .endcurrentEdit() 我忘了打电话给.endcurrentEdit()

BindingContext(DsEditObject1, "Object").EndCurrentEdit()

我忘了打电话给.endcurrentEdit()

BindingContext(DsEditObject1, "Object").EndCurrentEdit()

Sadly your BindingContext is holding up the changes. 不幸的是,您的BindingContext阻止更改。 Normally SqlDataAdapter.Update will send the updates to the database immediately, but it looks like your BindingContext is holding all of it for you so that you can cancel it if you need to. 通常SqlDataAdapter.Update会立即将更新发送到数据库,但是看起来BindingContext正在为您保留所有更新,因此您可以根据需要取消更新。

I would get your DataSet out of the Context so that it will update immediately. 我会将您的DataSet移出Context,以便立即更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM