
6th August 2008, 01:21 AM
|
|
Junior Member
|
|
Join Date: Aug 2008
Posts: 1
Credits: 0
|
|
ASP.Net - Not Set To Instance of Object - Error when retrieving string from Query URL
In Visual Studio 2005, I get the error when trying to pull a query value from previous page:"System.NullReferenceException: Object reference not set to an instance of an object."Which refers to the line "string itemID = Request.QueryString["itemID"].ToString();"Here is some code:string itemID = Request.QueryString["itemID"].ToString(); SqlConnection dbConnect = new SqlConnection(ConfigurationManager.ConnectionStrin gs["PeanutConnectionString"].ToString()); SqlCommand getProduct = new SqlCommand("SELECT * FROM PRODUCTS WHERE itemID=" itemID , dbConnect); //Open the connection. dbConnect.Open(); SqlDataReader myData = getProduct.ExecuteReader(); if (myData.HasRows) { //Advance the first records. myData.Read();
|