Print Page | Close Window

Another Error.

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=11139
Printed Date: 29 March 2026 at 3:11am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Another Error.
Posted By: davidshq
Subject: Another Error.
Date Posted: 08 July 2004 at 11:45am

I know I'm posting a lot...But I really do try to figure this stuff out on my own...and can't. This is another section of code I'm writing for the Today in History Script. This is going to function as an editor. Here's the raw code:
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Data
Imports System.Data.OleDb

Public Class Editor
  Inherits Page
  Protected lblEvents as Label
  Private Sub Page_Load(sender as Object, e as EventArgs) Handles MyBase.Load
    Dim con as New OleDBConnection()
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=civilwar.mdb"
    con.Open
    Dim reader as OleDBDataReader
    Dim cmd as New OleDBCommand()
    cmd.Connection=con
    cmd.CommandText="Select * from tblToday"
    reader = cmd.ExecuteReader()
    Do WHILE reader.read()
    lblEvents.Text=lblEvents.Text
    lblEvents.Text &="<a href='" & reader("ID") & "'>" & "Edit." & "</a>"
    lblEvents.Text &= " - " & reader("mMonth") & "/" & reader("mDay") & "/"
    lblEvents.Text &= reader("mYear") & " - " & reader("mEvent") & "<br>"
    Loop
    reader.close()
    con.close()
  End Sub
End Class
Here's the error:
Object reference not set to an instance of an object.
Here's the stack trace:
[NullReferenceException: Object reference not set to an instance of an object.]
   Editor.Page_Load(Object sender, EventArgs e) +142
   System.Web.UI.Control.OnLoad(EventArgs e) +55
   System.Web.UI.Control.LoadRecursive() +27
   System.Web.UI.Page.ProcessRequestMain() +731
Thanks.
Respectfully,
David.



-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.



Replies:
Posted By: Mart
Date Posted: 08 July 2004 at 12:30pm
Can you show what line the error is on?


Posted By: davidshq
Date Posted: 08 July 2004 at 2:08pm
Not unless you know a way for me to get ASP.NET to display the line number. The trace stack and error is about all it gave me.

-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: davidshq
Date Posted: 08 July 2004 at 2:27pm

From what I'm seeing on Google so far...The error means generally that I failed to initialize a variable or a object...But I can't find any I failed to.
Respectfully,
David.



-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: Leeb65
Date Posted: 09 July 2004 at 2:42am

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=civilwar.mdb"
    Dim reader as OleDBDataReader
    Dim cmd as New OleDBCommand()
    cmd.Connection=con
    cmd.CommandText="Select * from tblToday"
    con.Open
    reader = cmd.ExecuteReader()

open the connection after you have assigned it to the command and after you have assigned the command text.

 



-------------
Lee

http://www.rheinsitemedia.de">


Posted By: Mart
Date Posted: 09 July 2004 at 2:45am
That wouldn't cause an Object reference not set to an instance of an object error.

Those are only caused when you do

Dim sb As StringBuilder
sb.Append("hi")

as opposed to

Dim sb As New StringBuilder
sb.Append("hi")


Posted By: Leeb65
Date Posted: 09 July 2004 at 2:53am

Here is my C# code and it works perfectly.

sqlSelectPage = new System.Data.SqlClient.SqlCommand();

sqlConn = new System.Data.SqlClient.SqlConnection();

this.sqlConn.ConnectionString = "packet size=4096;user id=sa;data source=\"(local)\";persist s" +

"ecurity info=True;initial catalog=RMSCMS;password=pw";

sqlSelectPage.Connection = sqlConn;

sqlSelectPage.CommandText = "SELECT Firma_Name, Channel, URL, MenuText, MenuType, Region, SubChannel, X, Y, H, W, SectionNr, Titel, Inhalt, VonDatum, ZuDatum, Zeigen, Template_Name, Template_Source FROM vwPages WHERE (Channel='" + Channel + "') AND (SubChannel='" + SubChannel + "')";

if(sqlSelectPage.Connection.State==ConnectionState.Closed)

sqlSelectPage.Connection.Open();

 

drPage = sqlSelectPage.ExecuteReader(CommandBehavior.CloseConnection);

 



-------------
Lee

http://www.rheinsitemedia.de">


Posted By: Leeb65
Date Posted: 09 July 2004 at 3:02am

a shot in the dark here as I am not sure myself without testing, but

Do WHILE reader.read()
lblEvents.Text=lblEvents.Text
lblEvents.Text &="<a href='" & reader("ID") & "'>" & "Edit." & "</a>"

is it possible this line is causing the error?


 



-------------
Lee

http://www.rheinsitemedia.de">


Posted By: davidshq
Date Posted: 09 July 2004 at 9:08am

No luck with either of those suggestions. :-( Will keep trying I guess.
Respectfully,
David.



-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: davidshq
Date Posted: 09 July 2004 at 10:29am

 - Your faces after realizing the problem.
 - My face after realizing the problem.
 - My face after being beaten by the collective webwiz.net forums community.
And the problem was....::drum roll::
I was using a code-behind file and in the actualy aspx file I had accidently set the text to lblEvents not the ID...So the script wasn't finding a Label control.
Respectfully,
David.



-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: dpyers
Date Posted: 09 July 2004 at 11:04am

If we all knew it all, there wouldn't be much to talk about.

 

I thought I made a mistake once... but I was wrong



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: davidshq
Date Posted: 09 July 2004 at 11:21am
lol. So are you not married or is your wife just always wrong when she tells you you are wrong?

-------------
- http://www.davemackey.net/" rel="nofollow - Dave Mackey - Virtual Home.


Posted By: dpyers
Date Posted: 09 July 2004 at 12:05pm
Originally posted by davidshq davidshq wrote:

lol. So are you not married or is your wife just always wrong when she tells you you are wrong?

lol - We have an understaning - I am always right! (but she is always righter)

-------------

Lead me not into temptation... I know the short cut, follow me.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net