2012-05-13 3 views
0

WP7의 로컬 데이터베이스에 DateStamp를 사용하여 데이터를 저장하려고합니다. 나는 MSDN Guidance을 따라 코드 아래 만들었습니다 : " '형식으로 변환 할 수 없습니다WP7, 로컬 데이터베이스, 날짜 시간 열의 캐스트 예외

private void StoreThisGame() 
{ 
    using (var db = new HistoricGameContext()) 
    { 
     if (!db.DatabaseExists()) 
      db.CreateDatabase(); 
     var game = new HistoricGame 
     { 
      DateStamp = DateTime.Now, 
      GameId = "1", 
      LongestSequence = _currentGame.LongestCorrectSequence, 
      Score = _currentGame.TotalPoints 
     }; 
     db.HistoricGames.InsertOnSubmit(game); 
     db.SubmitChanges(); //<- This is where it throws an InvalidCastException 
    }    
} 

그러나 db.SubmitChanges();는 메시지와 함께 InvalidCastException을 던지는 유지 :

[Table] 
public class HistoricGame 
{ 
    [Column(IsDbGenerated = true, IsPrimaryKey = true)] 
    public int Id { get; set; } 

    [Column] 
    public DateTime DateStamp { get; set; } 

    [Column] 
    public string GameId { get; set; } 

    [Column] 
    public int Score { get; set; } 

    [Column] 
    public int LongestSequence { get; set; } 

} 

public class HistoricGameContext : DataContext 
{ 
    public const string ConnectionString = "Data Source=isostore:/NumbersNerdDB.sdf"; 

    public HistoricGameContext() 
     :base(ConnectionString) 
    {} 

    public Table<HistoricGame> HistoricGames 
    { 
     get { return GetTable<HistoricGame>(); } 
    } 
} 

이의 데이터베이스에 기록하기 위해 호출된다 System.DateTime '을 입력하여'System.Byte [] '을 입력하십시오. "

데이터베이스 관련 문제를 지적하는 항목을 찾을 수 없으며 사용한 원래 예제에 DateTime이 포함되어 있지 않지만 Silverlightshow.net의 예제는 매우 비슷한 상황에서 DateTime을 사용합니다.

잘못된 장소를보고 있거나 내가 놓친 것이 있습니까?

+0

annoyingly, 나는 지금 그것을 나의 전화 위에서 테스트했다. 그리고 그것은 단지 잘 움직이는 것처럼 보인다. 만족스럽지는 않지만 베타 테스터가 없으므로 다른 전화기에서도 작동 할 것이라고 가정 할 수는 없으므로 에뮬레이터에서도 작동하지 않습니다. – Hans

답변

0

나는 비슷한 문제가있었습니다.

내 경우에는 내 테이블의 "서버 데이터 유형"속성 값이 누락되었습니다. DateTime으로 정의 된 "Type"속성을 가졌지 만 충분하지 않았습니다.