Hi, everybody,
The codes below run under VS2003 for a long time. I want to upgrade it to VS2005. VS2005 gives me some varning messages such as "Varibles shouldn't be used before being assigned".
My question is: Is it necessary to close sDa in my code?
'-------------------------------------------------------------------------------
Private Function MethodIDExist(B yVal iMethodID As Integer) As Boolean
Dim oCmd As New OleDbCommand
If ConnMethod.Stat e = ConnectionState .Closed Then ConnMethod.Open ()
With oCmd
.Connection = ConnMethod
.CommandType = CommandType.Sto redProcedure
.CommandText = "StoredProcedur eName"
.Parameters.Add ("", OleDbType.Integ er)
.Parameters(0). Value = iMethodID
End With
Dim sDa As OleDbDataReader
Try
sDa = oCmd.ExecuteRea der()
If sDa.Read() Then
Dim Num As Integer = sDa(0)
If Num 0 Then
sDa.Close()
Return True
End If
End If
If Not sDa.IsClosed Then sDa.Close()
Return False
Catch exc As Exception
MessageBox.Show (exc.ToString)
'************** *************** *************** *************** **********
If (Not sDa Is Nothing) AndAlso (Not sDa.IsClosed) Then sDa.Close()
'************** *************** *************** *************** **********
Return False
End Try
End Function
'--------------------------------------------------------------------------------
Thanks in advance,
Peter
The codes below run under VS2003 for a long time. I want to upgrade it to VS2005. VS2005 gives me some varning messages such as "Varibles shouldn't be used before being assigned".
My question is: Is it necessary to close sDa in my code?
'-------------------------------------------------------------------------------
Private Function MethodIDExist(B yVal iMethodID As Integer) As Boolean
Dim oCmd As New OleDbCommand
If ConnMethod.Stat e = ConnectionState .Closed Then ConnMethod.Open ()
With oCmd
.Connection = ConnMethod
.CommandType = CommandType.Sto redProcedure
.CommandText = "StoredProcedur eName"
.Parameters.Add ("", OleDbType.Integ er)
.Parameters(0). Value = iMethodID
End With
Dim sDa As OleDbDataReader
Try
sDa = oCmd.ExecuteRea der()
If sDa.Read() Then
Dim Num As Integer = sDa(0)
If Num 0 Then
sDa.Close()
Return True
End If
End If
If Not sDa.IsClosed Then sDa.Close()
Return False
Catch exc As Exception
MessageBox.Show (exc.ToString)
'************** *************** *************** *************** **********
If (Not sDa Is Nothing) AndAlso (Not sDa.IsClosed) Then sDa.Close()
'************** *************** *************** *************** **********
Return False
End Try
End Function
'--------------------------------------------------------------------------------
Thanks in advance,
Peter
Comment