我无法从本地数据库更新数据。这是我的代码:
private void appBarOkButton_Click(object sender, EventArgs e)
{
string selectedRowOrderId = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedRowOrderId))
{
int selectedID = int.Parse(selectedRowOrderId);
var query = from TblCustomers customer in orderDB.Customers
where customer.Id == selectedID
select customer;
TblCustomers editCustomer = query.FirstOrDefault();
if (editCustomer != null)
editCustomer.Name = txtBoxCustomerName.Text;
App.ViewModel.SaveChangesToDB();
// Return to the main page.
if (NavigationService.CanGoBack)
{
NavigationService.GoBack();
}
}
}
这是模范方面:
public void SaveChangesToDB()
{
orderDB.SubmitChanges();
}
当我尝试在数据库中更改某些内容时,Everythings在调试时看起来很正常。但最后没有任何改变。你能帮我吗?
答案 0 :(得分:1)
编辑页面
XAML:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="ToDoListBoxItemTemplate">
<TextBox HorizontalAlignment="Stretch" Text="{Binding ItemName,Mode=TwoWay}" FontSize="{StaticResource PhoneFontSizeLarge}"
Grid.Column="1" Grid.ColumnSpan="2"
VerticalAlignment="Top" Margin="-36, 12, 0, 0"
></TextBox>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<Grid x:Name="LayoutRoot" Background="Transparent">
<ListBox
x:Name="allToDoItemsListBox"
ItemsSource="{Binding AllToDoItems}"
Margin="12, 0, 12, 0" Width="440"
ItemTemplate="{StaticResource ToDoListBoxItemTemplate}" />
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
<shell:ApplicationBarIconButton
IconUri="/Images/appbar.check.rest.png"
Text="Save"
x:Name="newTaskAppBarButton"
Click="newTaskAppBarButton_Click"/>
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
代码背后:
public partial class EditPage : PhoneApplicationPage
{
public EditPage()
{
InitializeComponent();
DataContext = App.ViewModel;
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
App.ViewModel.SaveChangesToDB();
}
private void newTaskAppBarButton_Click(object sender, EventArgs e)
{
NavigationService.GoBack();
}
}
为我工作