2009-10-15 105 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列的要大一些。

相关问题