Cameron,
> The second to last lin of code in the below sub is causing VS2003 to tell
me
> that "Name 'SqlDR' is not declared" when obviously it is. It's also used
> just fine in the main code... any ideas????
No sqwlDR is not defined (in the current scope).
The Try Block (of the Try/Finally statement) introduces a new scope,
variables defined with in the Try block itself are local to that block. Any
Catch clause blocks & the Finally block are different scopes from the Try
block.
You are trying to use the sqlDR variable in the Finally block.
What I normally do is define the variables outside the try/finally
statement. Then in the Finally block, if its not Nothing dispose of it.
> Public Sub loadWOFromKEY()
Dim sqlDR As SqlDataReader
> Try
sqlDR = cmdObj.ExecuteReader()
> Finally
If Not sqlDR Is Nothing Then
sqlDR.Close()
End If
> End Try
Of course if you use the ExecuteReader with the CommandBehavior of Close
connection then the Finally is not needed.
Dim sqlDR As SqlDataReader =
cmdObj.ExecuteReader(CommandBehavior.CloseConnection)
Hope this helps
Jay
"Cameron Frasnelly" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> The second to last lin of code in the below sub is causing VS2003 to tell
me
> that "Name 'SqlDR' is not declared" when obviously it is. It's also used
> just fine in the main code... any ideas????
>
> *****CODE BELOW****
>
> Public Sub loadWOFromKEY()
>
> Try
>
> 'Setup the connection
>
> Dim connObj As SqlConnection = New
> SqlConnection(OpsDB_Module.ConnectionString())
>
> 'Setup the command to execute
>
> Dim cmdObj As SqlCommand = New SqlCommand("spWorkOrderFull_byKEY",
connObj)
>
> cmdObj.CommandType = CommandType.StoredProcedure
>
> '----add parameter to stored procedure
>
> Dim myParm As SqlParameter = cmdObj.Parameters.Add("@WorkOrderKEY",
> SqlDbType.Int)
>
> myParm.Value = 3333
>
> 'Open the connection
>
> connObj.Open()
>
> 'Grab the data into a reader object
>
> Dim sqlDR As SqlDataReader = cmdObj.ExecuteReader()
>
> If sqlDR.HasRows = False Then
>
> Me._ProblemTitle = "No Rows"
>
> End If
>
> '----LOTS O WORK - Get the column values
>
> Dim tmpString As String = sqlDR.GetName(0) 'Testing
>
> sqlDR.Read()
>
> Me._WorkOrderKEY = sqlDR.GetInt16(0)
>
> Me._Problem = sqlDR.GetString(sqlDR.GetOrdinal("Problem"))
>
> Me._Priority = sqlDR.GetInt16(sqlDR.GetOrdinal("Priority"))
>
> Me._ReceiveNOW = sqlDR.GetDateTime(sqlDR.GetOrdinal("ReceiveNOW"))
>
> sqlDR.Close()
>
> connObj.Close()
>
> Catch ex As Exception
>
> Me._Problem = ex.Message.ToString
>
> Finally
>
> sqlDR.Close()
>
> End Try
>
>
|