UPDATING数据集失败? [英] UPDATING Dataset Fails?

查看:281
本文介绍了UPDATING数据集失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据本文: http://msdn.microsoft.com/en -us / library / xzb1zw3x.aspx ,在数据集中插入/更改数据后,我需要调用UPDATE以将数据库数据与数据集数据同步。

According to this article : http://msdn.microsoft.com/en-us/library/xzb1zw3x.aspx , after I insert/change data in the dataset, I need to call the UPDATE to synchronize my database data with the dataset data.

我的问题是这样的:

我创建了一个名为dataset1.xsd的数据集,然后创建一个新的TableAdapter来执行我的INSERT查询,THEN I需要以某种方式让我的数据库知道数据集中的东西已经改变。

I have created a dataset called dataset1.xsd and then I create a new TableAdapter to do my INSERT query with, and THEN I need to somehow let my database know that the stuff in dataset has changed.

DataSet1TableAdapters.reservationsTableAdapter ta = new DataSet1TableAdapters.reservationsTableAdapter();

ta.Insert(LastName,Arrival,Departure);  // this is where I do the INSERT query

现在我应该更新数据集,我如何做到这一点?我上面发表的文章建议做这样的事情:

Now I should update the dataset, right? How do I do this? The article I posted above suggests doing something like this:

ta.Update(DataSet1.reservationsDataTAble);

但是,我不能这么做,因为:

However, I can't do this because:

错误 - 'myproject.DataSet1.reservationsDataTable'是类型,在给定上下文中无效。

Error - 'myproject.DataSet1.reservationsDataTable' is a 'type', which is not valid in the given context.

我尝试声明一个新的Dataset1 DataTable,然后更新它,但它仍然不会显示我的数据库中的任何更改。

I tried declaring a new Dataset1 DataTable, and then updating that, but it still won't show any changes in my database.

我知道,保存在DataSet中,因为当我稍后填写一个新的数据库时,记录就存在了。

I KNOW, however, that the changes are saved in the DataSet, because when I fill a new datatable later, the record is there.

编辑:感谢下面的评论, :

Thanks to the comments, below, I tried doing this for a change:

DataSet1.reservationsDataTable NDT = new DataSet1.reservationsDataTable();                   

DataSet1TableAdapters.reservationsTableAdapter ta = new DataSet1TableAdapters.reservationsTableAdapter();

ta.Insert(LastName,Arrival,Departure);

ta.Fill(NDT);   
ta.Update(NDT);

...我可以在调试器中看到NDT datatable DID实际上包含

... and I could see (in the debugger) that the NDT datatable DID in fact contain the data that was "INSERTED" and then filled into the data table.

但是, ta.Update(NDT); 仍未更新我的数据库...

However, the ta.Update(NDT); still did not update my database...

推荐答案

然而,ta.Update(NDT);仍然没有更新我的数据库意味着没有执行sql-insert并且没有异常。

I assume that However, the ta.Update(NDT); still did not update my database means that no sql-insert is executed and that yo get no exception.

这对你有用吗? / p>

does this work for you?

var myDataSet1 = new DataSet1();

var newReservation = myDataSet1.reservations.NewRow();

newReservation.LastName=...
newReservation.Arrival=...
newReservation.Departure=...

myDataSet1.reservations.AddreservationsRow(newReservation);

var ta = new DataSet1TableAdapters.reservationsTableAdapter();

ta.Update(myDataSet1.reservations);

这篇关于UPDATING数据集失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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