简体   繁体   English

插入数据库SQL Server Compact 3.5 Windows Phone

[英]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.

相关问题 SQL Compact Server 3.5 Orderby语句-Windows Phone - SQL Compact Server 3.5 orderby statement - windows phone Windows Phone中使用SQL Server Compact Tool 3.5的where子句 - Where clause in windows phone using sql server compact tool 3.5 从Windows Phone中的日期时间SQL Server Compact 3.5获取月份和年份 - Get month and year from datetime SQL server compact 3.5 in Windows Phone 在Windows Phone的SQL Server Compact工具3.5中添加新列时出错 - Error when added a new column in SQL Server Compact tool 3.5 in Windows Phone 以编程方式将表添加到Microsoft SQL Server Compact 3.5数据库 - Programmatically adding table to Microsoft SQL Server Compact 3.5 Database 从SQL Server Compact 3.5数据库填充treeView - Populate treeView from SQL Server Compact 3.5 database SQL Server Compact 3.5版数据库访问被拒绝 - SQL Server Compact edition 3.5 database acess is denied 使用TableAdapter将记录插入SQL Server Compact数据库 - Inserting a record into SQL Server Compact database using TableAdapter 使用sdf数据库(SQL Server Compact 3.5数据库文件)而不安装Microsoft sql server C# - Use sdf database(SQL Server Compact 3.5 database file) without installing Microsoft sql server C# 使用SQL Server Compact在Windows Phone 8中的页面之间传递参数 - Passing parameters between pages in Windows Phone 8 using SQL server compact
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM