Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB SQL
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
 
Thanks
 
PS: in my databasee (SQLSERVER) the field is Int
Posted 19-Mar-13 8:41am
Edited 19-Mar-13 8:46am
v2
Comments
Maciej Los at 19-Mar-13 13:51pm
   
Not clear...
Provide more details, like query, table structure, etc.

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
JSRPreguntas at 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 at 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 at 19-Mar-13 16:15pm
   
then should I modify my field to string?
OriginalGriff at 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 at 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 at 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 at 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
0 OriginalGriff 475
1 Maciej Los 349
2 Richard MacCutchan 220
3 BillWoodruff 219
4 Mathew Soji 160
0 OriginalGriff 8,759
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,269
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 19 Mar 2013
Copyright © CodeProject, 1999-2014
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