Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HttpRequest request = context.Request;
HttpResponse response = context.Response;
string fromdate1 = request["from"].ToString();
string fromdate = dateConvert1(fromdate1);
string todate1 = request["to"].ToString();
string todate = dateConvert1(todate1);
Posted
Comments
[no name] 11-Dec-14 0:34am    
Hi,

Put a break point and check. that all the values variables has the values.

e.g request["from"].ToString();

1. The first part from the 1st solution is OK, you are trying to use something that is not found in the request cache.

2.The solution is more simple, just to test with null and to get value from the cache that is already a string and not to use ToString().
C#
string fromdate1 = (request["from"] == null ? string.Empty : request["from"]); 

PS: Note that in the web application caches (like Session, Application, etc.), the data are saved by using boxing (as objects), than when you get something from cache you should use unboxing and not ToString(), like below:
C#
string userName = (string)Session["UserName"];

For more details about boxing and unboxing see in MSDN: http://msdn.microsoft.com/en-us/library/yz2be5wk.aspx[^]
 
Share this answer
 
Comments
Pratik Bhuva 11-Dec-14 3:29am    
5ed :)
Good One Sir.
Raul Iloc 11-Dec-14 4:42am    
Thank you for your vote!
This error saying that there is something "null".

C#
string fromdate1 = request["from"].ToString();

if you are getting error in this line there is possibility that request["from"] is null.
so if request["from"] is null then its not possible to write like...

C#
// if request["from"] is null then your code seems like...
null.ToString();
//This is not Allowed.


You better check if its null or not before you use this.
C#
string fromdate1 = !string.IsNullOrEmpty(request["from"]) ? request["from"].ToString() : string.empty;


Hope this Help.
 
Share this answer
 
v2

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