How do I load a list via a data set from SQL Server into ListView?
<p>I have what seems to be a simple question but its killing me trying to find out.</p>

<p>I have a form in which I have a ListView. In this ListView I would like to populate it with data from a SQL Server 2008 database table.</p>

<pre><code>public void LoadList()
{
   DataTable dtable = budget_MainDataSetReceipt.Tables["Receipt"];
   listView1.Items.Clear();

   for (int i = 0; i &lt; dtable.Rows.Count; i++)
   {
      DataRow drow = dtable.Rows[i];

      if (drow.RowState != DataRowState.Deleted)
      {
         ListViewItem lvi = new ListViewItem(drow["ReceiptID"].ToString());
         lvi.SubItems.Add(drow["DateCleared"].ToString());
         lvi.SubItems.Add(drow["CategoryID"].ToString());
         lvi.SubItems.Add(drow["Amount"].ToString());
         lvi.SubItems.Add(drow["Store"].ToString());
         lvi.SubItems.Add(drow["DateEntered"].ToString());

         listView1.Items.Add(lvi);
      }
   }
} 
</code></pre>

<p>I keep getting an </p>

<blockquote>
  <p>Object reference not set to an instance of an object</p>
</blockquote>

<p>error, and I can't figure out why. There are about 5 rows of data in my database, so in my mind, there should be 5 rows of data within the list view.</p>

<p>Can anyone tell me what I am missing? I can post more code if that would be helpful.</p>

<p>I have tried calling the <code>LoadList()</code> method in several ways:</p>

<ul>
<li>Before the method itself</li>
<li>With the <code>InitializeComponent()</code> method</li>
<li><p>I have tried the following syntax</p>

<pre><code>this.LoadList(); 
this.Form1.LoadList();`
</code></pre></li>
</ul>

<p>I have also tried to initialize the DataTables type with the following:</p>

<pre><code>DataTables dt = new DataTables //did not work
</code></pre>
