Getting NullReferenceException Error

lorena

Well-known member
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
All I want to do is put data into a grid. Here is my code:
Code:
Sub BindData()
    Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\intranet\databases\open_en.mdb"
    Dim objConn As New OleDb.OleDbConnection(strConnString)

    Dim strSQL As String = "SELECT  * FROM InsChange"
    Dim objCommand As New OleDb.OleDbCommand(strSQL, objConn)

    Dim objDA As New OleDb.OleDbDataAdapter
    objDA.SelectCommand = objCommand

    Dim objDS As New DataSet
    objDA.Fill(objDS)
    objConn.Close()
  
    grdRecs.DataSource = objDS
    grdRecs.DataBind()
  End Sub
I keep getting "Object reference not set to an instance of an object"
Any help would be appreciated.
 
The page builds with no errors. The error occurs when I try to preview the page in a browser window.
Here is the stack trace:
NullReferenceException: Object reference not set to an instance of an object.]
webforms.oe_test.BindData() in J:\WebForms\oe\oe_test.aspx.vb:50
webforms.oe_test.Page_Load(Object sender, EventArgs e) in J:\WebForms\oe\oe_test.aspx.vb:32
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750

Line 50 is
Code:
grdRecs.DataSource = objDS
I checked my query and, in the access database, it pulls the data in correctly but it looks like the dataset is null if I am reading it right.
 
Well, this is really bizarre. I started by commenting all the code out and adding it back a line at a time, changing nothing and now it works!
*argh*
thanks for your help though. I just wish I knew why it works now.
 
Back
Top