Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Another Error.
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Another Error.

 Post Reply Post Reply Page  12>
Author
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post Topic: Another Error.
    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.

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 08 July 2004 at 12:30pm
Can you show what line the error is on?
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
davidshq View Drop Down
Senior Member
Senior Member


Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
Post Options Post Options   Thanks (0) Thanks(0)   Quote davidshq Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Leeb65 View Drop Down
Groupie
Groupie


Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Leeb65 Quote  Post ReplyReply Direct Link To This Post 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.

 



Edited by Leeb65
Lee


Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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")
Back to Top
Leeb65 View Drop Down
Groupie
Groupie


Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Leeb65 Quote  Post ReplyReply Direct Link To This Post 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);

 



Edited by Leeb65
Lee


Back to Top
Leeb65 View Drop Down
Groupie
Groupie


Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Leeb65 Quote  Post ReplyReply Direct Link To This Post 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


Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.