0
我在Windows Phone 7中使用WCF數據服務,我想單擊保存關係數據我怎麼能這樣做?wcf數據服務保存單點擊關係數據
它認爲2表:類別和產品
我要保存數據的用戶界面:
從Cateogry表: -
類別編號:(自動遞增)
類別名稱:ABC來自產品表: -
ProductId :-(自動增量)
CategoryId: - ? (不知道我怎麼會檢索)
產品名稱:按鈕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));
}