0
我想找到旧的坐标,并用我的数据库中的新坐标替换为使用C#WPF。我得到这个错误请修正“字符串或二进制数据将被截断。 r n声明已终止”
字符串或二进制数据将被截断。\ r \ n此语句已终止
,我找不到什么问题。这是我的方法,我用:
public void updateEvent(string oldCord,string newCord, DateTime dropDate)
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "UPDATE Event SET Date = @newDate ,[email protected] WHERE Cordinate = @oldCord";
cmd.Parameters.AddWithValue("@newDate", dropDate);
cmd.Parameters.AddWithValue("@newCord", newCord);
cmd.Parameters.AddWithValue("@oldCord", oldCord);
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = connection;
cmd.ExecuteNonQuery();
}
}
抛出此异常是因为您试图将更多数据写入表中的字段而不是适合它。像'varchar(50)'字段中带有100个字符的“字符串”。所以问题是,字段'Cordinate'(应该可能被命名为'Coordinate')到底有多确切,以及您尝试写入'newCord'的时间有多长? – Corak
你应该看看[我们可以停止使用AddWithValue()了吗?](http://blogs.msmvps.com/jcoehoorn/blog/2014/05/12/can-we-stop-using-addwithvalue-already/)并停止使用'.AddWithValue()' - 它可能会导致意想不到的和令人惊讶的结果... –
这篇文章'http://stackoverflow.com/questions/17312558/database-insert-error-string-or-binary -data-将待截断“? – GSP