datatable works in C# winform but not ASP.NET

Posted by Charles Gargent on Stack Overflow See other posts from Stack Overflow or by Charles Gargent
Published on 2010-05-28T10:32:53Z Indexed on 2010/05/28 10:41 UTC
Read the original article Hit count: 272

Filed under:
|
|
|
|

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;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET