הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Monday, June 1, 2009 2:30 PM
Hi Guys,
I have writen a program in Visual Studio 2005 professional. Part of the program functions is to store customers details. Part of this details include a phone number.
I can add a customer and include his/her telephone no. which is 12 digits long. But when retreiving this customer I get the following error.
Value was either too large or too small for an Int32.Couldn't store <+23320805060> in Phone Column. Expected type is Int32.
The program runs fine If the phone numer is less than or = 9 digits. The datatype i am using is for the phone column is varchar(50). I have tried to change the data type to bigint, int and nvarchar(50) but the problem seems to persist. I am using the SQL database but i seem to be hitting a brick wall on this matter. Is there anyone ther who can point me to the right direction.
Thanks
Brandville
All replies (10)
Tuesday, June 2, 2009 1:06 PM ✅Answered
The problem probably is that your typed dataset still has integer type set on the phone column. Either change it manually or recreate the dataset schema.
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/thread/f6469c84-2805-4682-a864-02764e26af76 If this post is useful, mark it as answer.
Monday, June 1, 2009 2:44 PM
Store retrieved data in string, I dont think you need to store telephone number in integer, do you?Arjun Paudel
Monday, June 1, 2009 2:49 PM | 1 vote
Not on a computer I can check this on right now, but isn't one of the datatypes Long?
Int Data Type
Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647
Long Data Type (Visual Basic)
Holds signed 64-bit (8-byte) integers ranging in value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18).
Remarks
Use the Long data type to contain integer numbers that are too large to fit in the Integer data type.
Monday, June 1, 2009 3:01 PM
Hi jwavila
I definately agree with you. I also agree with Arjun that there is no need to store the data in integer format. However, the problem I have is this. In the table definition, the phone column has no long option. The relevant option that exist include varch and nvarch. How do I specify the correct data type to be held by the table so as to avoid the exception?
Thanks
Brandville
Monday, June 1, 2009 4:04 PM
You would be better off using a varchar with a length of 12 or more. Another reason for doing this is that you are probably storing + signs on the start of phone number as well. When stored as varchar, you could do other formatting on the phone numbers as well to make it easy to read such as "01782 431 002" or "0115 919 9119". If this post is useful, mark it as answer.
Tuesday, June 2, 2009 1:02 AM
Hi Guys,
From what i have gathered the its best for me to use varchar to store phone my numbers. I have changed the table definition to varchar(22). My program is able to add the phone numbers. The only problem is that when I try to retrieve the same record I get the same error i pointed out in the begining i.e.
"Value was either too large or too small for an Int32.Couldn't store <+25420280606> in Phone Column. Expected type is Int32."
I am using the following tableadapter;
'Me.CustomersTableAdapter.Fill(Me.NewLwashVideoDataSet.Customers)
to retrieve the record.
What can I do to avoid this bug? As i said before if i use phone numbers with alength of <=9 then there is no error.
I am really looking for a solution for this.
Thanks
Brand Ville
Tuesday, June 2, 2009 1:02 PM
Hi,
I have tried reconfiguring my TA but i still get the same error.
"Value was either too large or too small for an Int32.Couldn't store <+25420280606> in Phone Column. Expected type is Int32."
I have even tried changing the phone column from the server explorer and tried to preview the data using the dataset fill method not on run time but still get the same error.
I am using an SQL database and I did change the table definition to varchar(22). I am not sure what else to do any ideas?
Thanks
Brand Ville
Tuesday, June 2, 2009 3:33 PM
Hi
Thanks for your feedback. I will make the changes suggested and will get back to you to let you know if it worked.
Thanks for your help guys.
Brand
Wednesday, June 3, 2009 2:22 AM
HI Guys,
I have managed to get the program to work. Its now retrieving the phone number. As Arjun and Codecruiser had said. The problem was with the TA. The dataset type was somehow still in integer type.
To solve the problem I had to go the dataset and in the Main Fill method use the query designer wizard to generate the Fill method again. (One must make sure that you click next to the end so as to generate the necessary select statments and get methods by the wizard). This generated another column for the phone. All i had to do was to delete the old phone column and use the new one and reconfigure the dataset in the data sources tab. Another thing to note that, since there is a new phone column I had to bind it to my controls on the form.
At least it now works.
What I learnt from this encounter is this. The problem came as a result of adding the phone column. The database did not originally have one. My initial data type was integer. Even though I reconfirgured my datasets after changing this to varchar it was not changing the TA dataset data type. The only way was to go through the reconfigure the dataset by using the main fill method wizard.
Please see the above link which will explain how adding or removing a column can be affected by the Main fill method.
Hope that helps
Brand
Wednesday, June 3, 2009 2:27 AM
Hi Arjun
I have done so.
Thanks for your help
Brand