title: Object reference not set to an instance of an object. Dropdownlist
body: <p>I'm getting the following error:</p>
  <blockquote>
  <p>Object reference not set to an instance of an object.</p>
  <p>Server Error in '/WebSite3' Application.</p>
  <p>Object reference not set to an instance of an object.</p>
  <p>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.</p>
  </blockquote>
  <p>Here is my code</p>
  <pre><code>Partial Class frmChoseIncident
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles      Me.Load
      
      Dim objCDBGuest As New CDBGuestProfile
      Dim objCGuest As New CGuestProfile
  
  
  
  
  
      Dim arrList As New ArrayList
  
      If Page.IsPostBack = False Then
  
          Dim intGuestID1 As Integer
          intGuestID1 = Request.QueryString(&quot;id&quot;)
          objCGuest = objCDBGuest.getOneIncident(intGuestID1)
  
          txtIncidentName.Text = objCGuest.IncidentName
          txtIncidentSummary.Text = objCGuest.IncidentSummary
          txtRoomRate.Text = objCGuest.RoomRate
          txtArrivalDate.Text = objCGuest.ArrivalDate
          txtDepartureDate.Text = objCGuest.DepartureDate
          txtGuestName.text = objCGuest.GuestName
          txtCompany.Text = objCGuest.GuestCompany
          txtIncidentDate.Text = objCGuest.IncidentDate
          txtAddedDate.Text = objCGuest.AddedDate
          txtRoomID.Text = objCGuest.RoomId
          txtPreparedBy.Text = objCGuest.PreparedBy
          txtDepartment.Text = objCGuest.Department
          txtGuestTime.Text = objCGuest.GuestTime
  
          lstHotel.SelectedItem.Value = objCGuest.Hotel
          txtAction.Text = objCGuest.Action
          txtCost.Text = objCGuest.Cost
          txtComplimentary.Text = objCGuest.Complimentary
          txtAmount.Text = objCGuest.Amount
          lstGlitchStatus.SelectedItem.Value = objCGuest.GlitchStatus
          lstGuestHistory.SelectedItem.Value = objCGuest.GuestHistory
          txtComments.Text = objCGuest.Comments
  
  
          lstHotel.SelectedItem.Enabled = False
          txtAction.ReadOnly = True
          txtCost.ReadOnly = True
          txtComplimentary.ReadOnly = True
          txtAmount.ReadOnly = True
          lstGlitchStatus.SelectedItem.Enabled = False
          lstGuestHistory.SelectedItem.Enabled = False
          txtComments.ReadOnly = True
  
  
  
          txtIncidentName.ReadOnly = True
          txtIncidentSummary.ReadOnly = True
          txtRoomRate.ReadOnly = True
          txtArrivalDate.ReadOnly = True
          txtDepartureDate.ReadOnly = True
          txtGuestName.ReadOnly = True
          txtCompany.ReadOnly = True
          txtIncidentDate.ReadOnly = True
          txtRoomID.ReadOnly = True
          txtPreparedBy.ReadOnly = True
          txtDepartment.ReadOnly = True
          txtGuestTime.ReadOnly = True
      End If
  
  End Sub
  </code></pre>
  <p>The Function</p>
  <pre><code> Public Function getOneIncident(ByVal pintGuestID1 As Integer) As CGuestProfile
      Dim objCmd As New MySqlCommand
      Dim objCn As New MySqlConnection(connectionString)
      Dim objAdapter As New MySqlDataAdapter
      Dim strSQL As String = &quot;&quot;
      Dim objDs As New DataSet
      Dim objDataRow As DataRow
  
      strSQL = &quot;SELECT * FROM tblGuestProfile WHERE strGuestCodeTI=&quot; &amp; pintGuestID1
      objCmd.CommandText = strSQL
      objCmd.Connection = objCn
      objAdapter.SelectCommand = objCmd
  
      objCn.Open()
  
      objAdapter.Fill(objDs, &quot;tblGuestProfile&quot;)
      objDataRow = objDs.Tables(&quot;tblGuestProfile&quot;).Rows(0)
      Dim objCGuestProfile As New CGuestProfile
  
      objCGuestProfile.GuestName = objDataRow.Item(&quot;strGuestNameTI&quot;)
      objCGuestProfile.GuestCompany = objDataRow.Item(&quot;strGuestCompanyTI&quot;)
      objCGuestProfile.ArrivalDate = objDataRow.Item(&quot;strArrivalDateTI&quot;)
      objCGuestProfile.DepartureDate = objDataRow.Item(&quot;strDepartureDateTI&quot;)
      objCGuestProfile.IncidentDate = objDataRow.Item(&quot;strIncidentDateTI&quot;)
      objCGuestProfile.AddedDate = objDataRow.Item(&quot;strAddedDateTI&quot;)
      objCGuestProfile.RoomRate = objDataRow.Item(&quot;strRoomRateTI&quot;)
      objCGuestProfile.RoomId = objDataRow.Item(&quot;intRoomTI&quot;)
      objCGuestProfile.PreparedBy = objDataRow.Item(&quot;strPreparedByTI&quot;)
      objCGuestProfile.Department = objDataRow.Item(&quot;strDepartmentTI&quot;)
      objCGuestProfile.GuestTime = objDataRow.Item(&quot;strTimeTI&quot;)
      objCGuestProfile.IncidentName = objDataRow.Item(&quot;strIncidentNameTI&quot;)
      objCGuestProfile.IncidentSummary = objDataRow.Item(&quot;strIncidentSummaryTI&quot;)
  
      objCGuestProfile.Hotel = objDataRow.Item(&quot;intHotelTI&quot;)
      objCGuestProfile.Action = objDataRow.Item(&quot;strActionTI&quot;)
      objCGuestProfile.Cost = objDataRow.Item(&quot;strCostTI&quot;)
      objCGuestProfile.Complimentary = objDataRow.Item(&quot;strComplimentaryTI&quot;)
      objCGuestProfile.Amount = objDataRow.Item(&quot;strAmountTI&quot;)
      objCGuestProfile.GlitchStatus = objDataRow.Item(&quot;intGlitchStatusTI&quot;)
      objCGuestProfile.GuestHistory = objDataRow.Item(&quot;intGuestHistoryTI&quot;)
      objCGuestProfile.Comments = objDataRow.Item(&quot;strCommentsTI&quot;)
      objCn.Close()
      Return objCGuestProfile
  End Function
  </code></pre>
  <p>The CGuestProfile</p>
  <pre><code>Imports Microsoft.VisualBasic
  
  Public Class CGuestProfile
  Private strGuestCodeTI As String
  Private strGuestNameTI As String
  Private strGuestCompanyTI As String
  Private strArrivalDateTI As String
  Private strDepartureDateTI As String
  Private strIncidentDateTI As String
  Private strAddedDateTI As String
  Private intRoomTI As String
  Private strRoomRateTI As String
  Private strPreparedByTI As String
  Private strDepartmentTI As String
  Private strTimeTI As String
  Private strIncidentNameTI As String
  Private strIncidentSummaryTI As String
  Private intHotelTI As Integer
  Private intGuestHistoryTI As Integer
  Private strComplimentaryTI As String
  Private intGlitchStatusTI As Integer
  Private strActionTI As String
  Private strCostTI As String
  Private strAmountTI As String
  Private strCommentsTI As String
  
  
  Public Property GuestId() As String
      Get
          Return strGuestCodeTI
      End Get
      Set(ByVal value As String)
          strGuestCodeTI = value
      End Set
  End Property
  
  Public Property GuestName() As String
      Get
          Return strGuestNameTI
      End Get
      Set(ByVal value As String)
          strGuestNameTI = value
      End Set
  End Property
  
  Public Property GuestCompany() As String
      Get
          Return strGuestCompanyTI
      End Get
      Set(ByVal value As String)
          strGuestCompanyTI = value
      End Set
  End Property
  
  Public Property ArrivalDate() As String
      Get
          Return strArrivalDateTI
      End Get
      Set(ByVal value As String)
          strArrivalDateTI = value
      End Set
  End Property
  
  Public Property DepartureDate() As String
      Get
          Return strDepartureDateTI
      End Get
      Set(ByVal value As String)
          strDepartureDateTI = value
      End Set
  End Property
  
  Public Property IncidentDate() As String
      Get
          Return strIncidentDateTI
      End Get
      Set(ByVal value As String)
          strIncidentDateTI = value
      End Set
  End Property
  Public Property AddedDate() As String
      Get
          Return strAddedDateTI
      End Get
      Set(ByVal value As String)
          strAddedDateTI = value
      End Set
  End Property
  
  Public Property RoomId() As Integer
      Get
          Return intRoomTI
      End Get
      Set(ByVal value As Integer)
          intRoomTI = value
      End Set
  End Property
  
  Public Property RoomRate() As String
      Get
          Return strRoomRateTI
      End Get
      Set(ByVal value As String)
          strRoomRateTI = value
      End Set
  End Property
  
  Public Property PreparedBy() As String
      Get
          Return strPreparedByTI
      End Get
      Set(ByVal value As String)
          strPreparedByTI = value
      End Set
  End Property
  
  Public Property Department() As String
      Get
          Return strDepartmentTI
      End Get
      Set(ByVal value As String)
          strDepartmentTI = value
      End Set
  End Property
  
  Public Property GuestTime() As String
      Get
          Return strTimeTI
      End Get
      Set(ByVal value As String)
          strTimeTI = value
      End Set
  End Property
  Public Property IncidentName() As String
      Get
          Return strIncidentNameTI
      End Get
      Set(ByVal value As String)
          strIncidentNameTI = value
      End Set
  End Property
  Public Property IncidentSummary() As String
      Get
          Return strIncidentSummaryTI
      End Get
      Set(ByVal value As String)
          strIncidentSummaryTI = value
      End Set
  End Property
  Public Property Hotel() As Integer
      Get
          Return intHotelTI
      End Get
      Set(ByVal value As Integer)
          intHotelTI = value
      End Set
  End Property
  
  Public Property Action() As String
      Get
          Return strActionTI
      End Get
      Set(ByVal value As String)
          strActionTI = value
      End Set
  End Property
  
  Public Property Cost() As String
      Get
          Return strCostTI
      End Get
      Set(ByVal value As String)
          strCostTI = value
      End Set
  End Property
  Public Property Complimentary() As String
      Get
          Return strComplimentaryTI
      End Get
      Set(ByVal value As String)
          strComplimentaryTI = value
      End Set
  End Property
  
  Public Property Amount() As String
      Get
          Return strAmountTI
      End Get
      Set(ByVal value As String)
          strAmountTI = value
      End Set
  End Property
  Public Property GlitchStatus() As Integer
      Get
          Return intGlitchStatusTI
      End Get
      Set(ByVal value As Integer)
          intGlitchStatusTI = value
      End Set
  End Property
  
  Public Property GuestHistory() As Integer
      Get
          Return intGuestHistoryTI
      End Get
      Set(ByVal value As Integer)
          intGuestHistoryTI = value
      End Set
  End Property
  Public Property Comments() As String
      Get
          Return strCommentsTI
      End Get
      Set(ByVal value As String)
          strCommentsTI = value
      End Set
  End Property
  End Class
  </code></pre>
  <p>If i take away the</p>
  <pre><code>lstHotel.SelectedItem.Value = objCGuest.Hotel
  lstGlitchStatus.SelectedItem.Value = objCGuest.GlitchStatus
  lstGuestHistory.SelectedItem.Value = objCGuest.GuestHistory
  lstHotel.SelectedItem.Enabled = False
  lstGlitchStatus.SelectedItem.Enabled = False
  lstGuestHistory.SelectedItem.Enabled = False
  </code></pre>
  <p>Then i can load the page, however the dropdownlist is empty.</p>
  <p>Hotel function</p>
  <pre><code>Public Function getAllHotelDropDownList() As ArrayList
      Dim objCn As New MySqlConnection(connectionString)
      Dim objCmd As New MySqlCommand
      Dim objAd As New MySqlDataAdapter
  
      Dim objDs As New DataSet
      Dim objDr As DataRow
  
      Dim strSQL As String = &quot;SELECT * FROM tblHotel&quot;
  
      Dim objArrayList As New ArrayList
      Dim objHotel As New CHotel
  
      objCmd.Connection = objCn
      objAd.SelectCommand = objCmd
      objCmd.CommandText = strSQL
      objCn.Open()
      objAd.Fill(objDs, &quot;tblHotelData&quot;)
  
      For Each objDr In objDs.Tables(&quot;tblHotelData&quot;).Rows
          objHotel = New CHotel
          objHotel.Hotel = objDr.Item(&quot;intHotelHO&quot;)
          objHotel.strHotel = objDr.Item(&quot;strHotelHO&quot;)
          objArrayList.Add(objHotel)
      Next
      Return objArrayList
  
  End Function
  Public Function getOneHotel(ByVal pstrHotelTI As Integer) As CHotel
      Dim objCmd As New MySqlCommand
      Dim objCn As New MySqlConnection(connectionString)
      Dim objAdapter As New MySqlDataAdapter
      Dim strSQL As String = &quot;&quot;
      Dim objDs As New DataSet
      Dim objDataRow As DataRow
  
      strSQL = &quot;SELECT * FROM tblHotel WHERE intHotelHO=&quot; &amp; pstrHotelTI
      objCmd.CommandText = strSQL
      objCmd.Connection = objCn
      objAdapter.SelectCommand = objCmd
  
      objCn.Open()
  
      objAdapter.Fill(objDs, &quot;tblHotel&quot;)
      objDataRow = objDs.Tables(&quot;tblHotel&quot;).Rows(0)
      Dim objCHotel As New CHotel
  
      objCHotel.strHotel = objDataRow.Item(&quot;strHotelHO&quot;)
      
      objCn.Close()
      Return objCHotel
  End Function
  End Class
  </code></pre>