The problem is with scope - you cannot declare variable in TRY and see it in CATCH. This same apply also for VB.
The second problem is with initialization of the variable - you cannot initialize variable in TRY and rely in CATCH that it is initialized, because initialization can also fail. You must initialize it before TRY. This does not apply for VB, because VB internally initializes variables for you.
The same applies for FINALLY. Here is C# workaround:
SqlDataReader dr = null; //INITIALIZATION
try
{
...
dr = sqlcmd.ExecuteReader();
...
}
catch InvalidOperationException ex //Sample exception handling
{
...
}
finally
{
if(dr != null)
dr.Close();
}
Plamen Ivanov
MCSD .NET Early Achiever and MCAD .NET Charter Member (VB .NET/SQL Server 2000)
MCSD (VB 6.0/SQL Server 2000) br>
VB (.NET) - what other language do you need in the whole Universe?...