Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 28th, 2004, 05:58 AM
eon eon is offline
Registered User
 
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default datareader/datagrid will not work

I'm having so much trouble I've been trying to solve the following problem for hours and hours. what I'm trying to do is output an grid from a table, i'm using code behind and outputting to an <asp:datagrid>, or trying to, I had some severe problem with trying to make a login searching for username/password and couldn't output the userID but I solved it. somehow I think the problems are related, anyway, here's the code

        Dim dgrSongLog As DataGrid
        Dim strConnection As String = Application("strconnection")
        Dim objConnection As New SqlConnection(strConnection)
        objConnection.Open()
        Dim strProcName = "SELECT * FROM tblSongLog WHERE uid ='" & Request.QueryString("uid") & "' ORDER BY inserted DESC"
        Dim objCommand As New SqlCommand(strProcName, objConnection)
        Dim objReader As SqlDataReader = objCommand.ExecuteReader()

        dgrSongLog.DataSource = objReader
        dgrSongLog.DataBind()


AND HERE'S THE ERROR MESSAGE

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 54: Dim objReader As SqlDataReader = objCommand.ExecuteReader()
Line 55:
Line 56: dgrSongLog.DataSource = objReader
Line 57: dgrSongLog.DataBind()
Line 58:



it doesn't seem the matter if I'm trying with oledb or sql, datagrid och datareader, it just won't budge on the instansiating. I'm pulling my hair here.

Sincerely
Bennie

 
Old January 28th, 2004, 09:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Maybe as an alternative, use a SQLDataAdapter and pass the data into a data set. If you still get an error, then it may be either the uid is not coming back to the query, or something else... What is your connection string, and how does the user log into the system? Is the querystring value coming back, or is it blank?

Brian
 
Old January 28th, 2004, 11:30 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Dim dgrSongLog As DataGrid

The datagrid hasn't been instantiated.

Why are you dimming a datagrid there? The datagrid should already exist as a variable within the page class. Are you using codebehind or inline code?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Paging of Datagrid cannot work annie_stwg ASP.NET 1.0 and 1.1 Basics 5 March 21st, 2006 07:29 PM
Paging problem with datareader and datagrid alyeng2000 ASP.NET 1.0 and 1.1 Basics 4 September 9th, 2004 02:31 AM
Using DataReader() aadz5 ASP.NET 1.0 and 1.1 Basics 12 November 21st, 2003 06:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.