Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

Variable XYZ is used before it has been assigned a value

leave a comment »

Sometimes you fall in the condition where you might require to put try and catch block after just declaring variable ad that creates warning that Variable XYZ is used before it has been assigned a value.

The simple solution is , assign Nothing to the variable and check on the catch side.:

Dim BookingTran As Common.DbTransaction = Nothing
Try
   Dim db As Database = DatabaseFactory.CreateDatabase(Config.BookingDBName)
   BookingConn = db.CreateConnection
   BookingConn.Open()
   BookingTran = BookingConn.BeginTransaction()
Catch
   If Not BookingTran Is Nothing Then
      BookingTran.Rollback()
   End If
End Try

Advertisements

Written by Manish

November 5, 2010 at 12:09 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: