当其中一个表名称错误时尝试访问数据库时出错

时间:2013-06-07 13:27:21

标签: c# sql windows-phone-8

public partial class MainPage : PhoneApplicationPage
{  public MainPage()
   { InitializeComponent();
     LocationsDataContext db = new LocationsDataContext("Data Source = 'appdata:soldierDB.sdf'; File Mode = read only;");
     List<Locations> singleSoldiersLocs = new List<Locations>();
     singleSoldiersLocs = GetSoldierLocations(1555555);
   }
    public class LocationsDataContext : DataContext
    {   public LocationsDataContext(string ConnectionString)
                : base(ConnectionString)
            {
            }
            public Table<Locations> Locations
            {
            get{return this.GetTable<Locations>();}
            }
    }
    public static List<Locations> GetSoldierLocations(int soldierNumber)
    {   List<Locations> soldierList = null;

        LocationsDataContext db = new LocationsDataContext("Data Source = 'appdata:soldierDB.sdf'; File Mode = read only;"); 
        using (db)
        {
            IEnumerable<Locations> query = from soldier in db.Locations select soldier;   
            soldierList = query.ToList();//***Error==>An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in Microsoft.Phone.Data.Internal.ni.dll but was not handled in user code
        }
        return soldierList;
    }

    [Table]
     public class Locations
        {
            [Column(IsPrimaryKey = true, CanBeNull = false)]
            public int locationID{get;set;}

            [Column(CanBeNull = false)]
            public int soldierID {get;set;}

            [Column(CanBeNull = true)]
            public string location{get;set;}

            [Column(CanBeNull = true)]
            public string significance{get;set;}

            [Column(CanBeNull = true)]
            public string date{get;set;}

            [Column(CanBeNull = true)]
            public string latitude{get;set;}

            [Column(CanBeNull = true)]
            public string longitude{get;set;}

            [Column(CanBeNull = true)]
            public int ordinal{get;set;}
        }

我们有多个人看这个表和数据库架构以确保它们是相同的...但我们不断收到错误

  

发生了'System.Data.SqlServerCe.SqlCeException'类型的异常   在Microsoft.Phone.Data.Internal.ni.dll中但未在用户中处理   代码......

我们发现当我们使其他程序表有一个随机单词而不是真正的单词时,我们得到的是同样的错误,但现在我们不知道可能出错了什么

0 个答案:

没有答案