使用WPF将数据保存到数据库中
我有一个 WPF Visual Studio 2010 应用程序,其中有一个包含 2 个按钮和一个数据网格的窗口。我想修改数据网格中某些行的值,当按下“设置”按钮时,应该刷新数据网格。仅当按下“保存”按钮时才应保存已完成的更改。
刷新工作正常,但当我按下“保存”按钮时,我收到以下错误消息:
System.Data.UpdateException:更新条目时发生错误。有关详细信息,请参阅内部异常。 ---> System.Data.SqlClient.SqlException:字符串或二进制数据将被截断。 该语句已终止。
我在设置按钮的代码是:
myObjBase selected = this.dataGrid1.SelectedItem as nyObjBase;
myObj ist = new myObj ();
ist.field1= "";
ist.field2 = 22;
selected.myObj.Add(ist);
对于保存按钮,我有:
dataSource.SaveChanges();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您尝试插入列中的数据长度过长时,就会发生此错误。
您应该检查数据库中的最大长度属性,并确保用户无法发送比允许的更长的字符串。
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.