Click here to Skip to main content
13,049,684 members (65,743 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I'm having an issue when iserting the fields to my DB I have tried CInt, Integer.Parse and now Both SqlDbType and DBType and aall the Int16/32/64 that there are

when I excecute theNonquery I get Failed to convert parameter value from a String to a Int32.

insertCommand.Parameters.AddWithValue("@EJEMPLO_ZCODE",txtZipRegCoop.Text).SqlDbType = SqlDbType.Int


PS: in my databasee (SQLSERVER) the field is Int
Posted 19-Mar-13 7:41am
Updated 19-Mar-13 7:46am
Maciej Los 19-Mar-13 13:51pm
Not clear...
Provide more details, like query, table structure, etc.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What it is saying is that the value in txtZipRegCoop is not an integer.

Look at the actual content, and probably you need to report the problem to your user.

However, the whole idea of storing a postal / zip code in an integer may be a mistake - not every postal / zip code is an integer. Mine for example is two Alpha, one digit, an optional space, one digit and two Alpha.
JSRPreguntas 19-Mar-13 13:54pm
Ok, it does the same with the Telephone numbers they are Int and I have the same issue
also they are a masked textbox for formatting. (787) 777 - 777
OriginalGriff 19-Mar-13 15:00pm
Yes - and '(', ')' and '-' are not valid in an integer! (Neither is '+' except at the start which is valid in telephone numbers: it's the international dial prefix)
JSRPreguntas 19-Mar-13 16:15pm
then should I modify my field to string?
OriginalGriff 19-Mar-13 16:31pm
I would, yes.
If it's a "real" number - as in something your want to do math with, compare, average or whatever, then store it as a number. If it isn't (and a telephone number rarely is, leading zeroes for example can be important) then it should be a string.
JSRPreguntas 19-Mar-13 16:34pm
Thank You , can you ask me one more question? I want to always show one of the number I already have (autonumber) from the other table how can I achive this? I have been reading also the SqlDataReader and Can't make a single Select and show all my field plz help.
OriginalGriff 19-Mar-13 16:47pm
Sorry? That doesn't make a lot of sense as it is - remember I can't see your screen, and try explaining in a bit more detail.
JSRPreguntas 19-Mar-13 16:58pm
Sorry, I would like to know how to retrieve all the data o a column using a SELECT statement.
Someone from CodeProject refere to SqlDataAdapter on the MSDN but after trying a couple of times and reading I can't get to work with it,

And also I tried DELETING statement but same thing happen

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100