Click here to Skip to main content
15,867,780 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hye, i have following code of line, where the Parent_ID datatype is int?
from database it can return integer or null,when returns null ,it is gotten by a problem?....................................help me plz.......................


Parent_ID= int.Parse(dr["Parent_ID"].ToString());
Posted

1 solution

dr["Parent_ID"].ToString() is not always a valid int i.e. it could return null too. then parhaps you should try to use int.TryParse function to do the cast. Check this for more details: http://www.dotnetperls.com/int-tryparse[^]
 
Share this answer
 
Comments
Zubair SE 19-Jun-13 1:44am    
no it is same here,should i use the Parent_ID type int? for the senerio(from database it can return integer or null,)
Rahul Rajat Singh 19-Jun-13 1:47am    
With tryparse you will have to use int?. Why not check for null before trying to parse or convert. you can check of null value if the variable can contain only null other than valid int values.
Zubair SE 19-Jun-13 4:37am    
i have another issue with asp:menu control i have bind it dynamically but now how can i navigate to another page by clicking its child root only, no javascript/jquery
is working here

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