本文介绍了Windows phone 8:无法创建表(本地数据库),在mydb.submitchanges()中断。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的数据库代码

public class DbDataContext : DataContext
{ public DbDataContext()
    : base("Data Source=isostore:/MainDb.sdf")
{
    if (false == this.DatabaseExists())
        this.CreateDatabase();
}

public Table<S_List> FigureList;
}
[Table]
public class S_List
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Id { get; set; }
[Column]
public int s_publicfigureid { get; set; }
[Column]
public string s_name { get; set; }
[Column]
public Uri s_imageurl { get; set; }
}



这里是我如何向表添加条目的代码


and here is the code how i add entries to table

 private void wish_Checked(object sender, RoutedEventArgs e)
{
ToggleImageButton tgl = sender as ToggleImageButton;
var selectedItem = tgl.DataContext as User;
mydb.FigureList.InsertOnSubmit(new S_List
{
s_publicfigureid = selectedItem.publicfigureid,
s_name = selectedItem.name,
s_imageurl = selectedItem.imageurl,
});
mydb.SubmitChanges();
}



这是我得到的错误 System.Data中出现'System.Data.SqlServerCe.SqlCeException'类型的第一次机会异常。 Linq.ni.dll 在mydb.SubmitChanges();


And this is error i get A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.Linq.ni.dll at line mydb.SubmitChanges();

推荐答案

mydb.SubmitChanges();

by

by

// Submit the change to the database.
           try
           {
               mydb.SubmitChanges();
           }
           catch (Exception d)
           {
               Console.WriteLine(d);
               // Make some adjustments.
               // ...
               // Try again.
               mydb.SubmitChanges();
           }


这篇关于Windows phone 8:无法创建表(本地数据库),在mydb.submitchanges()中断。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 19:58