473,383 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

try keyword causing problems

I've got some code that I'm trying to enclose in a try/catch block. This
code is in the Page_Load() method of the code-behind for an .aspx page.

On the line where the "try" keyword is, I'm getting the error "Object
reference is not set to an instance of an object". Why would I get that on
the "try" keyword. I've copied the code below, and you can see that I've
commented out the extra code to the point where all I have is the
Page_Load() event and the try/catch block. What could be causing this?
public void Page_Load(object sender, System.EventArgs e)

{

//string sSQL;

try

{

/*

OleDbConnection2.Open();

sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";

daStatements = new OleDbDataAdapter(sSQL,OleDbConnection1);

daStatements.Fill(dsStatements);

Response.Write( "Record count = " +

dsStatements.Tables[0].Rows.Count.ToString());
string sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";

daStatements = new OleDbDataAdapter(sSQL,OleDbConnection1);

daStatements.Fill(dsStatements,"Statements");

DropDownList1.DataSource = dsStatements.Tables["Statements"];

DropDownList1.DataTextField = "Statement_In_Brief";

DropDownList1.DataValueField = "Statement_ID";

DropDownList1.DataBind();

Response.Write("test");
OleDbConnection1.Close();

*/

}

catch(Exception e)

{

//Response.Write(e.ToString);

}

} // end Page_Load() event
Nov 16 '05 #1
2 1927
Hi there,

are you sure that the OleDbConnection2 is being instantiated before calling
the Open() method?
If "Yes", then check the same for the UI elements you're using - i doubt
that the problem is with them , though - they should be initialized by the
designer inside the InitializeComponent() method.

So - check if the OleDbConnection2 var is being initialized. Or just put an
extra line on top of it - something like:

OleDbConnection2 = new OleDbConnection(["connectionstring goes here"]);

Cheers,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA, MCT
eAgility LLC

"Curt Emich" <ce****@comcast.net> wrote in message
news:3f********************@comcast.com...
I've got some code that I'm trying to enclose in a try/catch block. This
code is in the Page_Load() method of the code-behind for an .aspx page.

On the line where the "try" keyword is, I'm getting the error "Object
reference is not set to an instance of an object". Why would I get that on the "try" keyword. I've copied the code below, and you can see that I've
commented out the extra code to the point where all I have is the
Page_Load() event and the try/catch block. What could be causing this?
public void Page_Load(object sender, System.EventArgs e)

{

//string sSQL;

try

{

/*

OleDbConnection2.Open();

sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";

daStatements = new OleDbDataAdapter(sSQL,OleDbConnection1);

daStatements.Fill(dsStatements);

Response.Write( "Record count = " +

dsStatements.Tables[0].Rows.Count.ToString());
string sSQL = "SELECT Statement_Id,Statement_In_Brief FROM Statements";

daStatements = new OleDbDataAdapter(sSQL,OleDbConnection1);

daStatements.Fill(dsStatements,"Statements");

DropDownList1.DataSource = dsStatements.Tables["Statements"];

DropDownList1.DataTextField = "Statement_In_Brief";

DropDownList1.DataValueField = "Statement_ID";

DropDownList1.DataBind();

Response.Write("test");
OleDbConnection1.Close();

*/

}

catch(Exception e)

{

//Response.Write(e.ToString);

}

} // end Page_Load() event

Nov 16 '05 #2
"Curt Emich" <ce****@comcast.net> wrote in
news:3f********************@comcast.com:
I've got some code that I'm trying to enclose in a try/catch
block. This code is in the Page_Load() method of the
code-behind for an .aspx page.

On the line where the "try" keyword is, I'm getting the error
"Object reference is not set to an instance of an object". Why
would I get that on the "try" keyword. I've copied the code
below, and you can see that I've commented out the extra code to
the point where all I have is the Page_Load() event and the
try/catch block. What could be causing this?


Curt,

Just to clarify: the exception is occurring on the "try" keyword even
with all of the other code commented out?

If that's the case, and if you are using Visual Studio 2002, there's
a bug in VS2002 where the debugger would highlight the wrong line
when an exception occurred. There's a patch on MSDN.

If you're not using VS2002, could you please give more info:

- .Net version
- Which IDE you are using (VS2003, SharpDevelop, etc.)
- Version of Windows
- A small complete code sample demonstrating the problem, or
if that's not possible, then expand the code fragment
you posted so it includes more code from before and after
where the exception occurred.

Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
14
by: lawrence | last post by:
To call I would do something like: $headline = McSelectJustOneField::callDatastore("cbHeadline"); Is this the correct use of the static keyword, to implement a Singleton design?
12
by: Jack | last post by:
Hi, Is it recommended to use the var keyword when declaring a variable? IE lets me create a variable with var, then create the same one again with no problem. Also it lets me create a...
18
by: tweak | last post by:
What's the best way to use extern when using multiplefiles that is easiest to maintain? Is it best to declare: extern int a; in a header file and include the header file in all files except...
14
by: Zeng | last post by:
Would somebody know when we should seal a class? Shouldn't all classes be open up for inheritance? Thanks!
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
2
by: Curt Emich | last post by:
I've got some code that I'm trying to enclose in a try/catch block. This code is in the Page_Load() method of the code-behind for an .aspx page. On the line where the "try" keyword is, I'm...
4
by: PauloFor | last post by:
In this code : public abstract class DCMenuAgrupado { Object x = this; }
23
by: raashid bhatt | last post by:
what is restrict keyword used for? eg int *restrict p;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.