I want use a database in my app, but there are some errors:
An exception of type ‘System.Data.SqlServerCe.SqlCeException’ occurred in Microsoft.Phone.Data.Internal.ni.dll but was not handled in user code
If there is a handler for this exception, the program may be safely
continued.
It occurs on this:
if (true == db.PersonData.Any())
and
db.PersonData.InsertOnSubmit(newData);
The code worked on wp7….how do you fix it?
Thx~
[Table]
public class CPersonData
{
[Column]
public string Lat { get; set; }
[Column]
public string Lon { get; set; }
[Column]
public string SelectShopType { get; set; }
[Column]
public DateTime UpdateTime { get; set; }
}
public class DataBase : DataContext
{
public Table<CPersonData> PersonData;
public DataBase(string strConnection) : base(strConnection)
{
if (false == this.DatabaseExists())
this.CreateDatabase();
}
}
using (var db = new DataBase("Data Source=isostore:/FindTea.sdf"))
{
CPersonData newData = new CPersonData();
newData.Lat = "";
newData.Lon = "";
newData.SelectShopType = "1,2,3";
db.PersonData.InsertOnSubmit(newData);
db.SubmitChanges();
}
I found the problem!!!I didn’t put a primary key in this table, so when I add this
The App doesn’t crash!!!!