Problem with CAST NOT VALID


Author
Message
Tony Charpentier
Tony Charpentier
StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)
Group: StrataFrame Users
Posts: 10, Visits: 81
hello,

I' have a little problem when i call a BO with type System.Int32.

ex:
this.TXT_ETAGETOT.Text                  = oAffairesBo.etage.ToString().Trim();


My error message :

Le cast spécifié n'est pas valide.

Description : Une exception non gérée s'est produite au moment de l'exécution de la requête Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.

Détails de l'exception: System.InvalidCastException: Le cast spécifié n'est pas valide.

Erreur source:

Ligne 2742 : get
Ligne 2743 : {
Ligne 2744 : return (System.Int32)this.CurrentRow["etage"];
Ligne 2745 : }
Ligne 2746 : set


Have you an idea ?

thanks
Tony

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Tony,

Couple of things here:
  1. You don't need to TRIM() the value since an integer converted to string would result in a trimmed value.
  2. What is the value of oAffairesBo.etage ? if it is Null, DBNull or Nothing, then you have to setup the NULL Value option in the Business Object Mapper (BOM) to Return Alternate on Null and set the NULL Replacement Value to 0 (zero)
  3. Ultimately and the preferred way to handle this is to cast the value instead of using the ToString
      • ex: this.TXT_ETAGETOT.Text = Cstr(oAffairesBo.etage);
Good luck and welcome to the forums!!!

Edhy Rijo

Olivier
Olivier
StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)StrataFrame User (326 reputation)
Group: StrataFrame Users
Posts: 96, Visits: 805
Edhy Rijo (4/25/2012)
Hi Tony,

Couple of things here:
  1. You don't need to TRIM() the value since an integer converted to string would result in a trimmed value.
  2. What is the value of oAffairesBo.etage ? if it is Null, DBNull or Nothing, then you have to setup the NULL Value option in the Business Object Mapper (BOM) to Return Alternate on Null and set the NULL Replacement Value to 0 (zero)
  3. Ultimately and the preferred way to handle this is to cast the value instead of using the ToString
      • ex: this.TXT_ETAGETOT.Text = Cstr(oAffairesBo.etage);
Good luck and welcome to the forums!!!



Hello,

I work with tony, and yes you re right about Trim(),
just i want to say, the value of oAffairesBo.etage is 0 by default if is empty. So the value isn't null.

We can't to do Cstr cause it's vb language but we have Convert.toString, and it's stay the same problem,
we can't cast the value.

the cast is not valid.

Do you know WHy ?


thanks
Olivier

==============================================
Asp.net C# - Strataframe - telerik
==============================================
Michel Levy
Michel Levy
StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Hi Olivier,

Where and how do you enforce the zero value instead of the null? is it in the BO mapper, as Edhy shows you? it seems that you're confused with the default value, and these are two different things.

Salut Olivier,

A quel endroit et comment forces-tu la valeur zéro à la place de Null? Est-ce que c'est dans le BO mapper, comme Edhy te l'indique? j'ai l'impression que tu confonds avec la valeur par défaut, ce sont des concepts différents.
Tony Charpentier
Tony Charpentier
StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)StrataFrame Beginner (38 reputation)
Group: StrataFrame Users
Posts: 10, Visits: 81
Hello Michel,

In my table the fields "Etage" is 0 value.

And in the Bo Object Mapper , i click on the custom field properties [etage],
i put in "NULL Value Option" => Don't Allow nulls
And Null replacement Value i put " 0 "

Have any idea ?

thanks
Michel Levy
Michel Levy
StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Tony,

That's it! saying "don't allow Null", you ask your BO to reject NULL, and by consequence, to throw an error if there are NULLS... exactly the opposite you want Crying I think it is a side effect of the french grammer order and minding (opposite as the american mainding). And that's what I've seen in the code of the BO Designer you sent to me.

In the BO Mapper, you need to choose Generic on Null, or get/set a specific value (as I show you in the french speaking StrataFrame forum)

------

En français maintenant...

Eh paf! en choisissant "Don'allow Null", tu demandes à ton BO de refuser les NULL, et donc il te lève une erreur s'il en trouve. c'est pile poil le contraire de ce que tu veux Crying Je pense que c'est la conséquence des la façon de penser et de construire la grammaire française (à l'opposé de la grammaire anglo-américaine). Et c'est ce que j'ai vu dans le code du BO Designer que tu m'as envoyé.

Dans le BO Mapper,il te faut choisir Generic on Null, ou forcer une valeur précise pour le get/set, comme je te le montre sur le forum francophone.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search