title: VB.Net exception: Object reference not set to an instance of an object
body: <p>I'm currently working on coding a web page for a school project. This site is supposed to be a simple online store where people can order prints of artwork. The specific page I'm working on has a Drop Down List (ddlArt) that is bound to my database and displays a list of the different art pieces available. When the user selects one of the items, all the information on that item is pulled from the database and displayed on the page in a variety of labels and such. The only thing is that I'm getting a null reference exception error saying "Object reference not set to an instance of an object" when I go to try to run the page. I got the same error on a homework assignment earlier in the year and managed to get it fixed, but I can't remember what I did and I can't get help from school until next week, so I thought I'd try my luck on here. Here's my code:</p>
  
  <pre><code>    Private selectedArt As Art
  
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)     Handles Me.Load
          If Not IsPostBack Then
              ddlArt.DataBind()
          End If
          selectedArt = Me.GetSelectedArt
          lblArtID.Text = selectedArt.ArtID()
          lblArtName.Text = selectedArt.ArtName()
          lblCaption.Text = selectedArt.Caption()
          lblDescription.Text = selectedArt.Description()
          imgArt.ImageUrl = "~/images/" &amp; selectedArt.FileName()
      End Sub
  
  
      Private Function GetSelectedArt() As Art
          Dim artTable As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
          artTable.RowFilter = "ArtID = '" &amp; ddlArt.SelectedValue &amp; "'"
          Dim artRow As DataRowView = artTable(0)
  
          Me.imgArt.ImageUrl = "~/images/" &amp; artRow("FileName")
  
          Dim art As New Art
          art.ArtID = artRow("ArtID").ToString
          art.ArtName = artRow("ArtName").ToString
          art.Caption = artRow("Caption").ToString
          art.Description = artRow("LongDescription").ToString
          art.FileName = artRow("FileName").ToString
          Return art
      End Function
  </code></pre>
  
  <p>And here's the code for the Art class, in case anybody is interested:</p>
  
  <pre><code>    Public Class Art
          Public Property ArtID As Integer
          Public Property ArtName As String
          Public Property ArtType As String
          Public Property Caption As String
          Public Property FileName As String
          Public Property Description As String
      End Class
  </code></pre>
  
  <p>When I get the error, it highlights the <code>artTable.RowFilter = "ArtID = '" &amp; ddlArt.SelectedValue &amp; "'"</code> line in the GetSelectedArt function. I've tried comparing it to my corrected homework assignment that I mentioned, but I can't seem to find the problem. My VB is a little fuzzy because it's been awhile since I actually took the class. Any suggestions? Thanks a bunch!</p>