Friday, February 24, 2012

Help: Object reference not set to an instance of an object.

I am getting the Object reference not set to an instance of an object. error. Here is the code:


string conString;
conString = ConfigurationSettings.AppSettings["anonConnection"];

SqlConn = new SqlConnection(conString);
SqlComm = new SqlDataAdapter("usp_SelectProductList", SqlConn);

SqlComm.InsertCommand.CommandType = System.Data.CommandType.StoredProcedure;

SqlComm.InsertCommand.Parameters.Add(new SqlParameter("prod_type", SqlDbType.VarChar, 20));
SqlComm.InsertCommand.Parameters["prod_type"].Value = m_productType;

DataSet dsProducts = new DataSet();
SqlComm.Fill(dsProducts, "Products");

here is the error:


Line 46: SqlComm = new SqlDataAdapter("usp_SelectProductList", SqlConn);
Line 47:
Line 48: SqlComm.InsertCommand.CommandType = System.Data.CommandType.StoredProcedure;
Line 49:
Line 50: SqlComm.InsertCommand.Parameters.Add(new SqlParameter("prod_type", SqlDbType.VarChar, 20));

[NullReferenceException: Object reference not set to an instance of an object.]
Yocaher.Products.SelectProductList() in e:\inetpub\wwwfndfl\yocaher\classes\clsproducts.cs:48
Yocaher.products.Page_Load(Object sender, EventArgs e) in e:\inetpub\wwwfndfl\yocaher\products.aspx.cs:30
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724

any help would be GREATLY appreciated!


SqlComm.InsertCommand.CommandType = System.Data.CommandType.StoredProcedure;
SqlComm.InsertCommand.Parameters.Add(new SqlParameter("prod_type", SqlDbType.VarChar, 20));
SqlComm.InsertCommand.Parameters["prod_type"].Value = m_productType;

remove the insertcommand in the above lines.

hth

No comments:

Post a Comment