Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error Occurs:"Object reference not set to an instance of an object."

Error Occurs:"Object reference not set to an instance of an object."

Scheduled Pinned Locked Moved ASP.NET
help
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chiari
    wrote on last edited by
    #1

    Hi, I met problem when run my application. I select a supplier from the combox. First time when I selected, the SupplierName and SupShortName displayed out nicely in the textbox. However, when I select another Supplier from the same combox, it pop out this error to me: "Object reference not set to an instance of an object." Below is the attached code. Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim drApSupplier As SqlDataReader Dim cmdApSupplier As SqlCommand cmdApSupplier = New SqlCommand("LookupApSupplier", SqlConnection1) cmdApSupplier.CommandType = CommandType.StoredProcedure SqlConnection1.Open() drApSupplier = cmdApSupplier.ExecuteReader() While (drApSupplier.Read()) lstApSupplier.Items.Add(drApSupplier("Supplier")) End While lstApSupplier.Items.Add("Please Select Supplier") lstApSupplier.SelectedIndex = lstApSupplier.Items.Count - 1 End Sub Private Sub lstApSupplier_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstApSupplier.SelectedIndexChanged Dim strApSupplier As String = Trim(CStr(lstApSupplier.SelectedItem)) Dim drApSupplier As SqlDataReader If Not (strApSupplier) = "Please Select Supplier" Then Try Dim cmdApSupplier As SqlCommand cmdApSupplier = New SqlCommand("LookupSupplier", SqlConnection2) cmdApSupplier.CommandType = CommandType.StoredProcedure Dim sqlParam As New SqlParameter sqlParam = cmdApSupplier.Parameters.Add("@Supplier", SqlDbType.Char, 7) sqlParam.Value = strApSupplier SqlConnection2.Open() drApSupplier = cmdApSupplier.ExecuteReader() drApSupplier.Read() txtSupplierName.Text = Trim(CStr(drApSupplier("SupplierName"))) txtSupShortName.Text = Trim(CStr(drApSupplier("SupShortName"))) Catch ex As Exception MessageBox.Show(ex.Message & " " & ex.StackTrace & " " & ex.Source) Finally drApSupplier = Nothing SqlConnection2 = Nothing End Try Else Exit Sub End If End Sub Please help. Thanks in advance, Chiari

    P 1 Reply Last reply
    0
    • C Chiari

      Hi, I met problem when run my application. I select a supplier from the combox. First time when I selected, the SupplierName and SupShortName displayed out nicely in the textbox. However, when I select another Supplier from the same combox, it pop out this error to me: "Object reference not set to an instance of an object." Below is the attached code. Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim drApSupplier As SqlDataReader Dim cmdApSupplier As SqlCommand cmdApSupplier = New SqlCommand("LookupApSupplier", SqlConnection1) cmdApSupplier.CommandType = CommandType.StoredProcedure SqlConnection1.Open() drApSupplier = cmdApSupplier.ExecuteReader() While (drApSupplier.Read()) lstApSupplier.Items.Add(drApSupplier("Supplier")) End While lstApSupplier.Items.Add("Please Select Supplier") lstApSupplier.SelectedIndex = lstApSupplier.Items.Count - 1 End Sub Private Sub lstApSupplier_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstApSupplier.SelectedIndexChanged Dim strApSupplier As String = Trim(CStr(lstApSupplier.SelectedItem)) Dim drApSupplier As SqlDataReader If Not (strApSupplier) = "Please Select Supplier" Then Try Dim cmdApSupplier As SqlCommand cmdApSupplier = New SqlCommand("LookupSupplier", SqlConnection2) cmdApSupplier.CommandType = CommandType.StoredProcedure Dim sqlParam As New SqlParameter sqlParam = cmdApSupplier.Parameters.Add("@Supplier", SqlDbType.Char, 7) sqlParam.Value = strApSupplier SqlConnection2.Open() drApSupplier = cmdApSupplier.ExecuteReader() drApSupplier.Read() txtSupplierName.Text = Trim(CStr(drApSupplier("SupplierName"))) txtSupShortName.Text = Trim(CStr(drApSupplier("SupShortName"))) Catch ex As Exception MessageBox.Show(ex.Message & " " & ex.StackTrace & " " & ex.Source) Finally drApSupplier = Nothing SqlConnection2 = Nothing End Try Else Exit Sub End If End Sub Please help. Thanks in advance, Chiari

      P Offline
      P Offline
      Panthesh_Shah
      wrote on last edited by
      #2

      Put If(!IsPostback) condition in page load event.So that when selectedindex changed event occurs it doesn't load the dropdown box again.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups