2010-01-18 2 views
1

s'il vous plaît me dire comment mettre en œuvre Nullable paramètre de type chaîne dans vb.nets'il vous plaît aidez-moi à créer Nullable paramètre de chaîne dans Vb.NET

Fonction:

sub savedetail(byval name as string, byval age as integer) 
if name isnot nothing then 
some work 
end if 
end sub 

je l'appelle comme la chose

savedetail(nothing,34) //here is giving me format exception 

exception: System.FormatException: la chaîne d'entrée n'était pas dans un format correct.

Maintenant, je suis placer la fonction exect .. s'il vous plaît me dire où je fais erreur:

Function savedetails(ByVal db As DSLibrary.DataProviders.SqlProvider, ByVal name As String, ByVal cityId As Integer, ByVal addr1 As String, ByVal addr2 As String, ByVal phone As String, ByVal fax As String, ByVal zip As String, ByVal contactfname As String, ByVal contactlname As String, ByVal randomcode As String, ByVal reservationEmail As String, ByVal email As String, ByVal url As String, ByVal description As String, ByVal locationInfo As String, ByVal amenities As String, ByVal roomDetails As String, ByVal latitude As Double, ByVal longitude As Double, ByVal enabled As Integer, Optional ByVal hotelId As Integer = Nothing, Optional ByVal checkDuplicate As Boolean = True, Optional ByVal DSPartner As Integer = Nothing, Optional ByVal category As String = Nothing, Optional ByVal rating As Integer = Nothing) As Integer 

appel:

savedetails(db, hotelname, 0, address, Nothing, Nothing, Nothing, postal, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, hotelinfo, Nothing, service, Nothing, Convert.ToDouble(lat), Convert.ToDouble(longi), 1, Convert.ToInt32(hotelid), False, dspartnerid) 
+0

Le texte exact de l'exception s'il vous plaît. – Bobby

+2

Votre exemple fonctionne bien. Il doit y avoir quelque chose d'autre qui se passe. –

+0

Etes-vous sûr que l'exception FormatException ne provient pas de votre routine 'un peu de travail'? –

Répondre

5

Errrhm. Une chaîne est nullable par défaut car c'est un type de référence.

Modifier après avoir fourni plus d'informations: L'un des Convert.ToDouble() et Convert.ToInt32() lancent probablement cette exception. Utilisez le débogueur et définissez un point d'arrêt sur l'appel et inspectez les paramètres pour ces conversions ou déplacez-les en dehors de l'appel.

+0

mais il me donne erreur ... laissez-moi éditer ma question et s'il vous plaît jeter un oeil à nouveau –

+0

oui vous avez raison ... convet.todouble était exception de jet ... –

Questions connexes