Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15067

vb.NET, cannot close open recordset

$
0
0
Hello:

H have come code (full listing below), that will not allow me co close an open recordset. I feel like I've done this 1000 times, so its the usual nonsense with small issues takling up 90% of the time. Obviously, I am not seeing something here.

I do not want to change the structure to use a more modern technique, because this is simply a quick lookup.

Thank you for any help you can provide...
Code:

        MessageBox.Show(rs.State) ' rs.State = 1!!!
        rs.Close() ' Error, Operation is not allowed in this context



Code:

    Private Sub CheckJobSheetStartDate()
        Dim connectionString As String = "Provider=sqloledb;Data Source=SAGE\SQLEXPRESS;Initial Catalog=JobSheet;Integrated Security=SSPI;"

        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset

        Dim sql As String = "SELECT Started FROM [JobSheet].[dbo].[JobInfo] WHERE JobNo = '" & cboJobNo.Text & "' "
        Debug.WriteLine(sql)

        cn.Open(connectionString)
        rs.Open(sql, cn, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockPessimistic)

        MessageBox.Show(rs.State) ' rs.State = 1!!!

        rs.MoveFirst()
        Do While Not rs.EOF
            Dim Started As Date = rs.Fields("Started").Value
            Dim NewStart As Date = FormatDateTime(Now, DateFormat.ShortDate)
            If Started = #1979-01-01# Then
                rs.Fields("Started").Value = NewStart

            End If

            ' Only one part
            ' rs.MoveNext()

            Exit Do

            Loop

        rs.Close() ' Error, Operation is not allowed in this context
        cn.Close()

    End Sub


Viewing all articles
Browse latest Browse all 15067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>