Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Casting Question
Message
 
 
À
31/03/2010 02:04:28
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01458169
Message ID:
01458280
Vues:
39
>>In this example, pRecordId is an instance of a SqlParameter class.
>>
>>This works
>>
>>int RetVal = Convert.ToInt32(pRecordId.Value);
>>
>>
>>This throws "Specified cast is not valid"
>>
>>int RetVal = (int)pRecordId.Value;
>>
>>
>>
>>Why?
>
>
>Because the dbType of pRecordId is declared as char ?
>
>This fails
>
>			var pRecordId = new SqlParameter("TheName", System.Data.SqlDbType.Char, 20);
>			pRecordId.Value = "20";
>
>			int RetVal = (int)pRecordId.Value;
>
>
>this works
>
>			var pRecordId = new SqlParameter("hello", System.Data.SqlDbType.Int, 4);
>			pRecordId.Value = 20;
>
>			int RetVal = (int)pRecordId.Value;
>
>			Console.WriteLine("{0}", RetVal);
>			Console.ReadLine();
>
I think here we need to use TryParse method or Convert class, if I recall correctly.
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