我在 Windows phone 7 中使用 WCF 数据服务,我想通过单击保存关系数据,我该怎么做?
它的想法 2 表:类别和产品
我想保存数据 UI:
从类别表:-
CategoryId :(自动递增)
CategoryName :abc从产品表:-
ProductId :-(自动增量)
CategoryId :- ?(不知道如何检索)
ProductsName : xyz
在按钮保存点击:
我想在适当的表中插入上述数据,我该怎么做?
我正在使用以下代码添加一个表数据:
try
{
context = new NorthwindEntities(NorthwindUri);
context.AddToProducts(product);
context.BeginSaveChanges(new AsyncCallback((result) =>
{
bool errorOccured = false;
// Use the Dispatcher to ensure that the
// asynchronous call returns in the correct thread.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
context = result.AsyncState as NorthwindEntities;
try
{
// Complete the save changes operation and display the response.
DataServiceResponse response = context.EndSaveChanges(result);
foreach (ChangeOperationResponse changeResponse in response)
{
if (changeResponse.Error != null) errorOccured = true;
}
if (!errorOccured)
{
MessageBox.Show("The changes have been saved to the data service.");
}
else
{
MessageBox.Show("An error occured. One or more changes could not be saved.");
}
}
catch (Exception ex)
{
// Display the error from the response.
MessageBox.Show(string.Format("The following error occured: {0}", ex.Message));
}
});
}), context);
}
catch (Exception ex)
{
MessageBox.Show(string.Format("The changes could not be saved to the data service.\n"
+ "The following error occurred: {0}", ex.Message));
}