Results 1 to 3 of 3

Thread: vb.NET, cannot close open recordset

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    vb.NET, cannot close open recordset

    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
    - A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,116

    Re: vb.NET, cannot close open recordset

    If a change is being made to the recordset (which seems to be the case), you likely need to do an rs.Update before it will let you close it.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2013
    Location
    Minneapolis, MN
    Posts
    531

    Re: vb.NET, cannot close open recordset

    Quote Originally Posted by OptionBase1 View Post
    If a change is being made to the recordset (which seems to be the case), you likely need to do an rs.Update before it will let you close it.
    Thanks! That was it... Oh how I forget things...
    - A 'Hyperactive Member' trying to make a difference in a hyperactive world! And recently, I've been promoted to a 'Finatic Member,' whatever that means!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width