Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have C# coding...

In this I using stringbuilder...So when stringbuilder value converts to int it shows some error like
""Unable to cast object of type 'System.Text.StringBuilder' to type 'System.IConvertible"".

my coding is this

C#
if (username.Length > 0)
               {
                   StringBuilder details = objectfororderdetails.GetUsernamelocked(UserName, lockedout);
                   lbllockuser.Text = "Username and his/her Restaurants Successfully locked";
                   if (Convert.ToInt16(details) == 0)
                   {
                       txtlockuser.Text = null;
                       lbllockuser.Text = "Username and his/her Restaurants already locked";
                   }
               }


when runtime comes in if(Convert.ToInt16(details) == 0) it shows error like i mentioned above.


Give any solution for this
Posted
Comments
Zoltán Zörgő 5-Jun-12 3:05am    
What about some feedback for your other thread in this topic?

Try converting details.ToString() instead of details directly.
Example - if (Convert.ToInt16(details.ToString()) == 0)
 
Share this answer
 
v2
Comments
VJ Reddy 5-Jun-12 3:22am    
Good answer. 5!
Abhinav S 5-Jun-12 3:34am    
Thanks VJ.
Manas Bhardwaj 5-Jun-12 4:32am    
nice +5!
Abhinav S 5-Jun-12 5:34am    
Thank you.
Espen Harlinn 5-Jun-12 8:11am    
5'ed!
What about:
C#
Convert.ToInt16(details.ToString())

Remember for once, stringbuilder is not string, you cannot use it as a string.
 
Share this answer
 
Comments
VJ Reddy 5-Jun-12 3:22am    
Good answer. 5!
Zoltán Zörgő 5-Jun-12 4:33am    
Thanks
Hi,

You need to convert the StringBuilder back to a string

C#
StringBuilder details = new StringBuilder();
           details.Append("0");

           string detailsStr = details.ToString();

           if (detailsStr == "0")
           {

           }


Regards,
T
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900