Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi I am getting the following error while am trying to delete one record from my Grid.
Can anybody tell me what the exception mean.Thanx in advance..
"Conversion failed when converting the nvarchar value '29g' to data type int"

In my code its the following case

C#
else if (type == "DelDoctor")
     {
         objuserVO.DoctorID = Convert.ToInt32(Session["DoctorID"]);
         objuserVO.Transtype = "DEL";
         objRequestVO.addobject("AddDoctorsProfile", objuserVO);
     }
Posted
Updated 27-Aug-12 23:32pm
v3
Comments
Maciej Los 28-Aug-12 5:37am    
29g is not a valid integer value, that's why you get this error-message.
Debug program and check Session["DoctorID"] value.

The code you are showing is not related to your problem.

Like the error says "29g" cannot be converted to an integer value. Check the data you have entered and remove the "g" or anything which is not an number for all the rows in your database.

Add validation to your data entry to check for non integer values so this does not happen.
 
Share this answer
 
Comments
Legor 28-Aug-12 5:49am    
5ved for antitrolling (and correctness of the anwer ;)
Mehdi Gholam 28-Aug-12 6:01am    
Thanks Legor!
Legor 28-Aug-12 6:04am    
Your welcome, can you please offer the same service for my solution below?
Manas Bhardwaj 28-Aug-12 5:56am    
+5
Mehdi Gholam 28-Aug-12 6:01am    
Thanks Manas!
The error message allready says it all. You can not convert the characters '29g' to an integer representation. Of course 29g is not a number. Or can you tell me what would be the result of: "(29g + gst) * 5 = ?"
 
Share this answer
 
Comments
Legor 28-Aug-12 5:48am    
It seems some troll, probably the OP downvotes every answer out of missbelief or ignorance.
Mehdi Gholam 28-Aug-12 6:19am    
5'ed
Your Session["DoctorID"] contains "29g".
You are converting this value to int.
You cant convert "29g" to integer.
Normally Id fiel should be int. If you have used id field as nvarchar then rather than converting session to int convert to string.
 
Share this answer
 
Comments
Legor 28-Aug-12 5:49am    
5ved for antitrolling (and correctness of the anwer ;) ).
It is so clear the Convert class never will convert "29g" to int.
 
Share this answer
 
Comments
Legor 28-Aug-12 5:50am    
5ved for antitrolling (and correctness of the anwer ;)

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