whats wrong with my sqlread?

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
here is the code:
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            If ModuleUser.frmCRCurTestDetails.SqlConnectionGetRptTitleValues.State = ConnectionState.Closed Then
                ModuleUser.frmCRCurTestDetails.SqlConnectionGetRptTitleValues.Open()
            End If
            ModuleUser.frmCRCurTestDetails.SqlSelectCommandGetRptTitleValues.Parameters("@RID").Value = ModuleUser.curResultID
            Dim sqlRead As SqlClient.SqlDataReader
            sqlRead = ModuleUser.frmCRCurTestDetails.SqlSelectCommandGetRptTitleValues.ExecuteReader(CommandBehavior.SingleResult)
            While sqlRead.Read
                MsgBox(sqlRead.GetSqlString(1).Value)
            End While
            ModuleUser.frmCRCurTestDetails.SqlConnectionGetRptTitleValues.Close()
        Catch Exp As SqlClient.SqlException
            MsgBox(Exp.Message, MsgBoxStyle.Critical, "SQL Error")
        Finally
            sqlRead.Close()
        End Try
    End Sub

it says that: sqlRead is not declared (the one that after "Finally" was highlighted), please help
 
1) It was opened.... using the .ExecuteReader....
2) IF it was an open/cloe problem, the error msg would be different.
3) The Dim needs to be OUTSIDE the Try...Catch...Finaly. Because it was dimmed in the Try, that's the only place it can be used.

-tg
 
thx techgnome, i worked it out earlier time, thats exactly what you pointed out, dim has to be outside the try. cheers~
 
Back
Top