title: DataTable works in WinForms but not in ASP.NET
body: <p>I have created a class that returns a datatable, when I use the class in a c# winform the dataGridView is populated correctly using the following code</p>
  
  <pre><code>DataTable dt = dbLib.GetData();
  if (dt != null)
  {
    dataGridView1.DataSource = dbLib.GetData();
  }
  </code></pre>
  
  <p>However when I try the same thing with ASP.NET I get a </p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>using the following code</p>
  
  <pre><code>DataTable dt = dbLib.GetData();
  if (dt != null)
  {
    GridView1.DataSource = dt;
    GridView1.DataBind();
  }
  </code></pre>
  
  <p>the dbLib class GetData2 is there to prove that it is nothing caused by SQlite or the data</p>
  
  <pre><code>public static DataTable GetData()
  {
    SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db");
    SQLiteCommand cmd = new SQLiteCommand("SELECT count(Message) AS Occurrences, Message FROM evtlog GROUP BY Message ORDER BY Occurrences DESC LIMIT 25", cnn);
    cnn.Open();
    SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    DataTable dt = new DataTable();
    dt.Load(dr);
    return dt;
  }
  
  public static DataTable GetData2()
  {
    DataTable dt = new DataTable();
    dt.Columns.Add(new DataColumn("Occurrences", typeof(string)));
    dt.Columns.Add(new DataColumn("Message", typeof(string)));
  
    DataRow dataRow = dt.NewRow();
    dataRow["Occurrences"] = "1";
    dataRow["Message"] = "a";
    dt.Rows.Add(dataRow);
    return dt;
  }
  </code></pre>
  
  <p>the asp code</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server"&gt;
    &lt;Columns&gt;
      &lt;asp:BoundField DataField="Occurrences" HeaderText="Occurrences"&gt;&lt;/asp:BoundField&gt;
      &lt;asp:BoundField DataField="Message" HeaderText="Message"&gt;&lt;/asp:BoundField&gt;
    &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  </code></pre>