Object reference not set to an instance of an object.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • farooqhussain786
    New Member
    • Aug 2006
    • 3

    Object reference not set to an instance of an object.

    "Object reference not set to an instance of an object."

    I had receive the above mention error I have load printer info in first combo box and when select value a event triggered and load values in second combo box using printer info but i am receiving subject mention error.
    Code:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            'txtUPCode.Attributes.Add("onclick", "showDiv('divQtyAddSidebar');")
            'txtUPCode.Attributes.Add("onfocus", "showDiv('divQtyAddSidebar');")
            'txtUPCode.Attributes.Add("onblur", "hideDiv('divQtyAddSidebar', this.value);")
    
            txtProductSearch.Attributes.Add("onfocus", "showDiv('divSearchSidebar');")
            txtProductSearch.Attributes.Add("onblur", "hideDiv('divSearchSidebar', this.value);")
    
    
    
            If Not IsPostBack Then
                ''Load Brand Name
                ddlSelectBrand.DataSource = wseCommerce.LoadBrand().Tables(0)
                ddlSelectBrand.DataTextField = wseCommerce.LoadBrand().Tables(0).Columns("ManufacturerName").ColumnName.ToString()
                ddlSelectBrand.DataValueField = wseCommerce.LoadBrand().Tables(0).Columns("ManufacturerCode").ColumnName.ToString()
                ddlSelectBrand.DataBind()
            End If
    
            LoadPageStateFromPersistenceMedium()
        End Sub
    
        Protected Sub ddlSelectBrand_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlSelectBrand.SelectedIndexChanged
            If ddlSelectBrand.SelectedValue <> "" Then
                ddlSelectCatridge.Enabled = True
                ddlSelectPrinter.Enabled = True
    
                'Load Printer against Brand Name
                Dim BrandName As String = ddlSelectBrand.SelectedItem.Text.ToString
                ddlSelectPrinter.DataSource = wseCommerce.LoadPrinter(BrandName).Tables(0) 'error Object reference not set to an instance of an object. 
                ddlSelectPrinter.DataValueField = wseCommerce.LoadPrinter(BrandName).Tables(0).Columns("PrinterName").ColumnName.ToString()
                ddlSelectPrinter.DataTextField = wseCommerce.LoadPrinter(BrandName).Tables(0).Columns("PrinterName").ColumnName.ToString()
                ddlSelectPrinter.DataBind()
            Else
                ddlSelectCatridge.Enabled = False
                ddlSelectPrinter.Enabled = False
            End If
        End Sub
    Last edited by Frinavale; Sep 7 '10, 04:13 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags, added the error message to the thread.
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    did you check if this statement has any tables . wseCommerce.Loa dPrinter(BrandN ame)

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      ASP.NET runs in a stateless environment. That means that when a request to the page occurs (whether it be the first time the page is loaded or because of a postback) all of the objects required in order to process the page are created...and when the response is sent to the browser, everything is destroyed.

      This means that wseCommerce does not exist unless you recreate it on subsequent page requests. It might be a good idea to store the results in Session or something so that you don't have to recreate it by connecting to the database.

      -Frinny

      Comment

      Working...