Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Databases 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 22nd, 2005, 06:04 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default prob w chapter 3-using visual studio.net

while implementing the first exec. in visual studio.net i got an err:
"
Object variable or With block variable not set.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:


Line 31: Dim objCommand As New SqlCommand(strSQL, objConnection)
Line 32: objConnection.Open()
Line 33: dgNameList.DataSource = objCommand.ExecuteReader()
Line 34: dgNameList.DataBind()
Line 35: objConnection.Close()


"

in my aspx.vb file i added:
Imports System.Web.UI.WebControls.DataGrid

and initiated: Dim dgNameList As DataGrid

any reason why???

It's my frst exec and im frustrated :(

tnx
 
Old January 22nd, 2005, 06:20 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

First of all, I don't think you should add this:

Imports System.Web.UI.WebControls.DataGrid

but this:

Imports System.Web.UI.WebControls

The latter is the Namespace you can import, while DataGrid is a class that lives inside that namespace.

Also, do you have an associated DataGrid in the ASPX page, or are you creating a DataGrid on the fly? If the latter is the case, you should create a new instance of your grid:

Dim dgNameList As New DataGrid


HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 22nd, 2005, 06:40 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar and tx 4 repling!

Although I dont create my DataGrid on the fly I add the New
as you suggested.

Well, it has iliminated the err page but now I don't get the recordset to the page.
I only get the <h4>First Example: Listing data from the Employees table</h4> tag.

I want to emphasize that when I'm running the page not divided to two files it's working fine.

so.... al im missing now is my recordset....

tx


 
Old January 22nd, 2005, 07:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Normally, you add a DataGrid to the ASPX page, and then add something like this to the Code Behind file:

Protected WithEvents dgNameList As System.Web.UI.WebControls.DataGrid

This hooks up the DataGrid in the code behind file to the control in the ASPX page. When you use New in the Code Behind file, you get a new DataGrid object that is not related to the one in the ASPX file (although you probably get an error due to a naming conflict)

So, make sure that the DataGrid you add to the ASPX page has an associated declaration in the code behind file.

If this doesn't help, can you post the relevant parts of your ASPX page an Code Behind file?


Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 22nd, 2005, 11:22 AM
Registered User
 
Join Date: Jan 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Thank you so much.

It's working now and I can move forward.

:)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual studio 6 or visual studio .NET chaitannyam Visual C++ 1 November 13th, 2005 09:26 AM
Visual Studio.Net manojbandgar .NET Framework 2.0 0 July 12th, 2005 06:57 AM
Visual Studio.NET vs C# Mike Smith Forum and Wrox.com Feedback 2 December 22nd, 2003 03:47 PM
Visual Studio.net cgmenon .NET Web Services 1 September 18th, 2003 09:04 AM





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