| Author |
Topic Search Topic Options
|
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 08 July 2004 at 12:30pm |
|
Can you show what line the error is on?
|
 |
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
davidshq
Senior Member
Joined: 29 July 2003
Location: United States
Status: Offline
Points: 299
|
Post Options
Thanks(0)
Quote Reply
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.
|
|
|
 |
Leeb65
Groupie
Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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")
|
 |
Leeb65
Groupie
Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
Leeb65
Groupie
Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
|
Post Options
Thanks(0)
Quote Reply
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
|
 |