473,395 Members | 1,639 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,395 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 1929
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;
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.