New Message on dotNET User Group Hyd

Need Help on Using

Reply
  Reply to Sender   Recommend Message 2 in Discussion
From: Anand Kumar

Hi,

 

Its a nice question , well USING and "try{} catch{} and finally{} block "  used for handling exception and cleaning the resources such as database connection and file stream, socket object etc .The USING statement make sure that resources are released even if an exception occurs .Note That the USING statement is used only for resources that implement IDisposable  where as finally block can be used for any type of cleanup operation.<o:p></o:p>

<o:p> </o:p>

For database example<o:p></o:p>

public string ConnectionString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=pubs";<o:p></o:p>

string sqlQuery="SELECT DISTINCT CurDate FROM CurMaster ORDER BY 1";<o:p></o:p>

Using( SqlDataAdapter cacheDataAdapter =  new SqlDataAdapter(sqlQuery,ConnectionString);<o:p></o:p>

{<o:p></o:p>

// fetch the data and display on the screen <o:p></o:p>

}<o:p></o:p>

<o:p> </o:p>

In this example the using statement takes care of exception if any while getting data from the database .<o:p></o:p>

<o:p> </o:p>

The other example is <o:p></o:p>

using( StreamReader SampleFile = new StreamReader("C:\\MySample.Txt")){<o:p></o:p>

          //read out the file in a string or pass to Business Object<o:p></o:p>

} // resource will clean here<o:p></o:p>

<o:p> </o:p>

You can do it through  try{} catch{} and finally{} block also<o:p></o:p>

<o:p> </o:p>

The USING statement mostly used only for resources that implement IDisposable.

 

am I answer to your query :-)

 

Cheers

Anand<o:p></o:p>


View other groups in this category.

Click here!
Also on MSN:
Start Chatting | Listen to Music | House & Home | Try Online Dating | Daily Horoscopes

To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.

Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.

If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.

Reply via email to