保存已编辑数据时格式异常 [英] Format exception when saving edited data

查看:77
本文介绍了保存已编辑数据时格式异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我为我认为应该非常直接的事情感到困惑.

当我尝试在数据网格中编辑并保存一些数据时,出现格式异常错误,这似乎很有趣,因为我可以插入并保存新记录,但是当我尝试通过单击绑定导航器上的保存图标来编辑保存时,得到此

Hi there, I''m kind of stumped with what I would think should be very straight forward.

When I try to edit and save some data in my datagrid I get a format exception error, seems funny because I can insert and save a new record but when I try to edit save by clicking the save icon on the binding navigator I get this

'Format exception unhandled':
{"@p7 : SMITH - Input string was not in a correct format."}



请清楚一点,我没有触摸"SMITH"部分,我只是在另一栏中更改了一些地址或电话号码的详细信息. 并且我还可以在数据库资源管理器>显示表数据"中打开表,并编辑保存任何行/列而不会出现问题?.

那么为什么会在运行时发生呢?
我想知道使用nvarchar()作为外键是一个坏主意吗?最好使用char()吗?




CUSTOMERID(SMITH)定义为NVARCHAR(5)唯一,是,主键号,允许的螺母号.

它也是称为ORDERS的子表的外键,我可以在没有问题的情况下插入和编辑保存.

可以立即使用的更新数据库的VB代码:



JUST to be clear I''m not touching the "SMITH" part i''m just changing some address or phone number details in another column. AND Also I can open the table in "DataBase Explorer>Show table data" and edit save any row/column without issue?.

So why does it happen at runtime?
I wonder is it a bad idea to use a nvarchar() as a foreign key? Is it preferable to use char() ?




CUSTOMERID (SMITH) is defined as a NVARCHAR(5) UNIQUE YES, PRIMARY KEY NO,ALLOW NULS NO.

it is also the foreign key to a child table called ORDERS which i can insert and edit save with no probs.

THE VB CODE TO UPDATE THE DB IS RIGHT OUT OF THE BOX:

Private Sub CustomerTableBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles CustomerTableBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.CustomerTableBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.CustomerWorkDataSet)

    End Sub


非常感谢您阅读这里的任何建议:)


Any suggestions here would be welcome many thanks for reading :)

推荐答案

您正在尝试将字符串解析为整数.如果无法对字符串进行解析,则会得到该异常.您应该验证用户在输入或单击按钮时输入的值.
You''re trying to parse a string to an integer. If the string cannot be so parsed you''ll get that exception. You should either be validating the value the user inputs when it''s input or when that button is clicked.


我正在发布信息仅供参考,因为我不打算这样做假装我理解我原来的问题在做错什么.

我放下了表,然后使用varchar而不是nvarchar重写了表,此后一切都很好.

也许有人可以在这里提供数据类型的最佳实践使用:-)
I''m posting just for information only as I''m not going to pretend I understand what I was doing wrong with my original question.

I dropped the tables and re-wrote them using varchar instead of nvarchar and everything was fine after that.

Maybe someone can offer up the best practise use of datatypes here :-)


这篇关于保存已编辑数据时格式异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆