datatable works in C# winform but not ASP.NET
- by Charles Gargent
Hi I have created a class that returns a datatable, when I use the class in a c# winform the dataGridView is populted corectly using the following code
dataGridView1.DataSource = dbLib.GetData();
However when I try the same thing with ASP.NET I get a
Object reference not set to an
instance of an object.
using the following code
GridView1.DataSource = dbLib.GetData();
GridView1.DataBind();
What am I doing wrong / missing
Thanks
EDIT
for the curios here is the dbLib class
public static DataTable GetData()
{
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db");
SQLiteCommand cmd = new SQLiteCommand("SELECT count(Message) AS Occurances, Message FROM evtlog GROUP BY Message ORDER BY Occurances DESC LIMIT 25", cnn);
cnn.Open();
SQLiteDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
DataTable dt = new DataTable();
dt.Load(dr);
return dt;
}