Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here is my code for database
C++
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
C++
 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();
}

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();
Posted
Updated 6-Feb-15 21:10pm
v2

1 solution

replace
C#
mydb.SubmitChanges();
by
C#
// Submit the change to the database.
           try
           {
               mydb.SubmitChanges();
           }
           catch (Exception d)
           {
               Console.WriteLine(d);
               // Make some adjustments.
               // ...
               // Try again.
               mydb.SubmitChanges();
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900