-
Dec 31st, 2020, 11:24 AM
#1
Thread Starter
Fanatic Member
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!
-
Dec 31st, 2020, 12:02 PM
#2
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.
-
Dec 31st, 2020, 12:19 PM
#3
Thread Starter
Fanatic Member
Re: vb.NET, cannot close open recordset
Originally Posted by OptionBase1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|