Bind SQLiteDataReader to GridView in ASP.NET

Posted by Charles Gargent on Stack Overflow See other posts from Stack Overflow or by Charles Gargent
Published on 2010-05-26T11:26:12Z Indexed on 2010/05/26 11:31 UTC
Read the original article Hit count: 369

Filed under:
|
|

Hi,

this is all rather new to me, but I have searched for a good while and cant find any idea why I cant get this to work, dr looks like it is populated but I get this nullreferenceexeception when I try to bind to the gridview

Thanks

code

        SQLiteConnection cnn = new SQLiteConnection(@"Data Source=c:\log.db");
        cnn.Open();
        SQLiteCommand cmd = new SQLiteCommand(@"SELECT * FROM evtlog", cnn);
        SQLiteDataReader dr = cmd.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        cnn.Close();

Codebehind

    <asp:ContentPlaceHolder ID="MainContent" runat="server">
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </asp:ContentPlaceHolder>

error

Object reference not set to an instance of an object.

at WPKG_Report.SiteMaster.Button1_Click(Object sender, EventArgs e) in C:\Projects\Report\Site.Master.cs:line 32 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET