2009-10-15 108 views
0

在這些更新之前,我有一個插入語句: 在db.sql變量上顯示錯誤。字符串或二進制數據將被截斷。該語句已被終止

Topic top = (from t in db.Topics 
       where t.id == id 
       select t).SingleOrDefault(); 

top.lastpost = username + maxdate; 


Category ca = (from c in db.Categories 
      where c.categoryid == cat 
      select c).SingleOrDefault(); 

ca.totaltopics = ca.totaltopics + 1; 
ca.posts = ca.posts + 1; 
ca.lastpost = username + maxdate; 
db.SubmitChanges();  

回答

4

聽起來像是top.lastpostca.lastpost(或兩者)在db上沒有足夠的空間來容納username + maxdate

檢查數據庫字段允許多少個字符,並更改字段以允許更多字符或減少輸出的長度 - 可能只存儲username + maxdate.ToString("yyyy-MM-dd")username + maxdate.ToString("yyyy-MM-dd HH:mm:ss")

0

該字符串比DB列的長度長,所以生成的數據不適合裏面。

1

我假設Topic.lastpostCategory.lastpost都是string s和username + maxdate連接兩個字符串。結果可能會比適用於各表中的lastpost列的要大一些。

相關問題