Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with integer conversion
Message
 
 
À
12/09/2013 11:46:38
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Application:
Web
Divers
Thread ID:
01582916
Message ID:
01583032
Vues:
25
>>I don't recommend to use AddWithValue as I already said. AddWithValue is a quick way and it often leads to troubles. I suggest to always be explicit and use Add syntax and exact type instead. It also helps to document and requires more strict programming.
>
>I have always used AddWithValue. What kind of problems have you seen and what commands would you replace it with? Something like this?
>
>oCommand.Parameters.Add("@AmendmentNumber")
>plus something else to set the value?
>
AddWithValue does not specify type and length of the parameter and makes the best guess. So, there may be cases when it comes wrong as the one you saw yesterday.

I use this syntax:
oCommand.Parameters.Add("@ParamName", SqlDbType.Int).Value = ParamValue;
For the char, varchar and decimal I can also add a length as 3rd parameter. This is for SqlCommand, for OleDbCommand you need to research the exact syntax which will be similar.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform