在通过 asp.net 将日期插入 SQL Server 2008 时发生错误。
插入语句
Insert into comment(CommentFrom, CommentTo, Comment, Cmntonscrap, Cmnttime)
Values('" + Session["UserName"] + "','" + email.Text.ToString() + "','" +
txt.Text.ToString().Trim() + "','" + cscrap.Text.ToString().Trim() +
"','" + DateTime.Now.ToString().Trim() + "')";
错误:
string or binary data would be truncated,Statement is terminating
最佳答案
你的问题不在于日期。
它的字符串数据对于您尝试插入数据的列(可能是 varchar)来说太大了。
我会检查您的 Comment
和 txt.Text
的长度,看看是否可以插入数据。
为您的DateTime
使用sql 类型datetime
。在文本列中存储日期是 inviting a lot of trouble .
- 需要更多的存储空间。
- 搜索这些数据将非常困难。
- 您永远无法更改时区。
关于c# - 在 asp.net 中插入日期时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12129763/