Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I need help with the below code I would like to generate it using CodeDom in C#.
Is there any way to do this?
If there is no way to do this in CodeDom is the any alternative way beside using statement?
            using (SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample))
           {
                using (SqlCommand cmd = con1.CreateCommand())
                {
 
                }
           }
Posted 16-Dec-12 23:34pm
drake24553
Edited 17-Dec-12 4:54am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I'm not particularly familiar with CodeDom, but a using statement can be rewritten using try-finally, for example:
 
(SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample))
{
    // code
}
 
can be written as:
 
SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample);
try
{
    // code
}
finally
{
    if (con1 != null)
    {
        con1.Dispose();
    }
}
  Permalink  
Comments
drake24 at 19-Dec-12 5:44am
   
thank you mr. lewax00 for your answer i will try the try finally catch statement to replace the using statement.
 
To others who have a solution i'll gladly accept and try yours.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 487
1 CPallini 345
2 OriginalGriff 240
3 George Jonsson 159
4 Abdul Samad KP 145
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100