Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
C#
 using (SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample))
{
     using (SqlCommand cmd = con1.CreateCommand())
     {

     }
}
Posted
Updated 17-Dec-12 4:54am
v2

1 solution

I'm not particularly familiar with CodeDom, but a using statement can be rewritten using try-finally, for example:

C#
(SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample))
{
    // code
}


can be written as:

C#
SqlConnection con1 = new SqlConnection(Core.ConnectionStringSample);
try
{
    // code
}
finally
{
    if (con1 != null)
    {
        con1.Dispose();
    }
}
 
Share this answer
 
Comments
drake24 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900