I want to find the old co-ordinate and replace it with a new co-ordinate in my Database using C# WPF. I got this error
String or binary data would be truncated.\r\nThe statement has been terminated
and I couldn't find what's the problem. This is my method that I used:
public void updateEvent(string oldCord,string newCord, DateTime dropDate)
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "UPDATE Event SET Date = @newDate ,Cordinate=@newCord 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();
}
}
stringwith 100 characters into avarchar(50)field. So the question is, how exactly is the fieldCordinate(should probably be namedCoordinate) defined and how long exactly is thenewCordyou try to write into it?.AddWithValue()- it can lead to unexpected and surprising results...