Bind SQLiteDataReader to GridView in ASP.NET
- by Charles Gargent
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)