[英]Inserting to database SQL Server Compact 3.5 windows phone
When I try to insert data into my database, SubmitChanges()
throws an exception: 当我尝试将数据插入数据库时, SubmitChanges()
引发异常:
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Phone.Data.Internal.ni.dll If there is a handler for this exception, the program may be safely continued. Microsoft.Phone.Data.Internal.ni.dll中发生了类型为'System.InvalidOperationException'的第一次机会异常。如果有此异常的处理程序,则可以安全地继续执行该程序。
I have tried reinstalling the app and reimporting the database context. 我尝试重新安装应用程序并重新导入数据库上下文。 What have I done wrong here? 我在这里做错了什么?
using (DatabaseContext context = new DatabaseContext(ConnectionString))
{
var monthBud = ((ListPickerItem)monthCat.SelectedItem).Content;
Budgets budgeting = new Budgets();
budgeting.MonthBud = monthBud.ToString();
budgeting.YearBud = yearInput.ToString();
budgeting.BudgetBud = Math.Round(float.Parse(budgetInput.Text), 2);
context.Budgets.InsertOnSubmit(budgeting);
context.SubmitChanges();
// MessageBox.Show(budgetInput.ToString());
NavigationService.GoBack();
}
Additional note: I have commented out the line budgeting.YearBud = yearInput.ToString(); 附加说明:我已注释掉budgeting.YearBud = yearInput.ToString();这一行。 and it works. 而且有效。 Is there something wrong with that line? 那条线有什么问题吗? Below is the XAML for that line. 下面是该行的XAML。
<TextBox Name="yearInput"
InputScope="Number"
TextWrapping="Wrap"
FontFamily="{StaticResource PhoneFontFamilyLight}"
BorderBrush="Silver"
/>
I don't see you are actually creating a database. 我看不到您实际上是在创建数据库。 Try adding this 尝试添加这个
if (!context.DatabaseExists())
{
context.CreateDatabase();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.