Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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."}


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:
VB
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 :)
Posted
Updated 17-Oct-11 6:26am
v6

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.
 
Share this answer
 
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 :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900