0

I have a WPF Visual Studio 2010 application with a window containing 2 buttons and a datagrid. I want to modify the values of some row from datagrid and when the "Set"-button is pushed the datagrid should be refreshed. The done changes should be saved only when a the Save button is pressed.

The refreshing works fine, but when I push the "save"-button I receive the following error message:

System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: String or binary data would be truncated. The statement has been terminated.

My code at set button is:

myObjBase selected = this.dataGrid1.SelectedItem as nyObjBase;      
myObj ist = new myObj ();    
ist.field1= "";   
ist.field2 = 22;  
selected.myObj.Add(ist);    

and for the save button I have:

dataSource.SaveChanges();                   

1 Answer 1

3

This error happens when the length of the data you're trying to insert into a column is to long.

You should check the max length property in your database and make sure that users can't send a longer string then is allowed.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! This was the problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.