473,320 Members | 1,950 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,320 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 1924
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.