473,406 Members | 2,633 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,406 software developers and data experts.

C#/.Net - Doubt how"Using" Statement is implimented

29
Hi all,

I have a doubt regarding the "Using" statement

if i write a code like this....

using (sqlDataReader)
{

do something ....

}


do I need to explicitly close the DataReader object or

will it be taken care off as i'm using the "Using" statement, will it close & dispose ?

I would like to know whats the best practice ?
Apr 1 '08 #1
2 1111
Shashi Sadasivan
1,435 Expert 1GB
that would be an appropriate syntax.
Anything inside a using statement should implement the IDisposable interface.
so that at the end of the using clause, the object is disposed.

However with your syntax you can still run into problems as you can still access the sqlDataReader as it will be disposed after the using clause.

The method would be to declare the datareader inside the using statement

using Statement (C#)
Apr 1 '08 #2
tim007
29
Thanks ..... i understood what u said.
Apr 1 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Peng Yu | last post by:
For example, at the beginning of the C++ program, I say "using namespace std;" However, in the middle of the program, I want to disable "using namespace std;". Do you know how to do that? ...
13
by: Squid Seven | last post by:
This is just bizarre. for the following snippet of code: #include <string> using std::string; I get the error message:
10
by: Andreas Müller | last post by:
Hi all, I have a class SwitchCursor, that implements IDisposable. Is it legal to use an object that is not assigned to a reference inside a using statement like this: using(new...
4
by: Philipp Sumi | last post by:
Hello all I have a thread that performs some simple I/O within a loop that runs on a separate thread. I used the using keyword to ensure the writer's disposal: using (writer) { while...
5
by: charliewest | last post by:
I've implemented the USING statement to ensure that my newly created sql connection closes when my method is finished using it. The USING statement is wrapped in try/catch error handling statement....
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
25
by: samjnaa | last post by:
Please check for sanity and approve for posting at python-dev. In Visual Basic there is the keyword "with" which allows an object- name to be declared as governing the following statements. For...
3
by: Wolfgang Meister | last post by:
Is there a way to let VisualStudio insert automatically (after pressing e.g. F7) missing "Using" statements at the top ? Or is there a menu which suggests inserts for using directives ? How...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.