Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 Source Error: 

Line 7:      protected void Page_Load(object sender, EventArgs e)
Line 8:      {
Line 9:          string strCat = Request.QueryString["Category"].ToString() 
Line 10:         string strBook = Request.QueryString["Book"].ToString() 
Line 11:         string strConn = ConfigurationManager.ConnectionStrings["BookStoreDBConnectionString1"].ToString() 
Source File: c:\Users\Asmaa\Documents\Visual Studio 2010\Projects\BOOKSTORE\BOOKSTORE\BooksDetails.aspx    Line: 9
Posted
Updated 25-May-11 17:05pm
v2

Request.QueryString["Category"] is null.

Do a null check first.
if(Request.QueryString["Category"] != null) 
{
     strCat = Request.QueryString["Category"].ToString()
}


and continue with that pattern.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 25-May-11 15:31pm    
Bug detected. A 5.
--SA
Instead of .ToString()

U can use Convert.ToString as it handles null values like

C++
Convert.ToString(Request.QueryString["Category"]);
 
Share this answer
 
simply try this
string strCat = Request.QueryString["Category"];
           string strBook = Request.QueryString["Book"];
           string strConn =  ConfigurationManager.ConnectionStrings["BookStoreDBConnectionString1"]!=null? ConfigurationManager.ConnectionStrings["BookStoreDBConnectionString1"].ToString(): string.Empty;
 
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