Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting this error once I have published the website in the website on the IIS. In VB ,there is no problem. but in IIS there is.


THIS IS THE ERROR,

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 150:            'Dropdown List in update
Line 151:            ExecuteSQL(2, "select * from ITEMINVENTORY where availability = 'Unique'")
Line 152:            cb_ItemListToUpdate.DataSource = ds.Tables(0).DefaultView
Line 153:            cb_ItemListToUpdate.DataValueField = "iteminventoryid"
Line 154:            cb_ItemListToUpdate.DataTextField = "Code"



 Source File:  C:\inetpub\wwwroot\Inventory\NewComponent.aspx.vb    Line:  152 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   Pin_AddComponents.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\Inventory\NewComponent.aspx.vb:152
   System.Web.UI.Control.LoadRecursive() +70
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177

  


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34209 



can someone help me? I tried so many ways from google but still got this error.
Posted

Your code assumed that the database query actually returned data. It's not and you're trying to use a property or method of an object that doesn't exist.

The error is telling you that either ds or ds.Tables(0) returned null.

In either case, you really need to check for the existence of your returned objects before you try to use them. Like
ExecuteSQL(2, "select * from ITEMINVENTORY where availability = 'Unique'")
If ds Is Nothing OrElse ds.Tables.Count = 0 Then
    ' What do you need to do if the database doesn't return anything??
Else
    cb_ItemListToUpdate.DataSource = ds.Tables(0).DefaultView
    ...

Your code is also badly written. What is ds? Where is it defined? What does ExecuteSQL do? How does it know about ds? Why are you using "class global" variables like this?
 
Share this answer
 
Oh silly me. It was just my connection string that has a problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900