P
Peter
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(ByVal iMethodID As Integer) As Boolean
Dim oCmd As New OleDbCommand
If ConnMethod.State = ConnectionState.Closed Then ConnMethod.Open()
With oCmd
.Connection = ConnMethod
.CommandType = CommandType.StoredProcedure
.CommandText = "StoredProcedureName"
.Parameters.Add("", OleDbType.Integer)
.Parameters(0).Value = iMethodID
End With
Dim sDa As OleDbDataReader
Try
sDa = oCmd.ExecuteReader()
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(ByVal iMethodID As Integer) As Boolean
Dim oCmd As New OleDbCommand
If ConnMethod.State = ConnectionState.Closed Then ConnMethod.Open()
With oCmd
.Connection = ConnMethod
.CommandType = CommandType.StoredProcedure
.CommandText = "StoredProcedureName"
.Parameters.Add("", OleDbType.Integer)
.Parameters(0).Value = iMethodID
End With
Dim sDa As OleDbDataReader
Try
sDa = oCmd.ExecuteReader()
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