H
Hexman
I've come up with an error which the solution eludes me. I get the
error:
It occurs when I attempt to add a new record. I've stripped out much
of the code, leaving the pertinent (I hope) info. I'm using MS Access
2003 as the database.
The error appears to be quite self-explanatary, but I've read about
the locktype an it seems correct. The "Current Recordset" I'm unsure
of. I just want to find out if the record is on file and if not, add
it, otherwise I'll update it.
Sounds simple, but I need help.
Thanks,
Hexman
---------------------------------------------------------------------------------------------------
Imports System.Data.OleDb
'
'
'
Public Class Form1
Inherits System.Windows.Forms.Form
'
'
'
Public db As ADODB.Connection
Public C As ADODB.Command
Public POrstData As ADODB.Recordset
Private Sub DoUpdate()
'make connection and open database
db = New ADODB.Connection
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & txtDatabaseDir & "HRMDB.MDB" &
";Persist Security Info=False"
db.Open()
C = New ADODB.Command
C.ActiveConnection = db
C.CommandType = ADODB.CommandTypeEnum.adCmdText
'create and open record set
POrstData = New ADODB.Recordset
POrstData.Open("PurOrd", db,
ADODB.CursorTypeEnum.adOpenkeyset,
ADODB.LockTypeEnum.adLockOptimistic, True)
End Sub
Private Sub UpdateProcess()
C.CommandText = "Select PODate, POLoc, POItem FROM PurOrd " & _
"where PODate = #" & SelectedDate & "# and POLoc = '" & strLoc & "' "
& _
"AND POItem = " & CInt(strItem)
POrstData = C.Execute
If POrstData.EOF = True Then
POrstData.AddNew() <======= Fails with Error =====
POrstData.Fields.Item("PODate").Value = "#" & strDate & "#"
POrstData.Fields.Item("POLoc").Value = strLoc
POrstData.Fields.Item("POItem").Value = CInt(strItem)
POrstData.Update()
Else
MsgBox("Record Found: #" & SelectedDate & "# " & strLoc & " "
& CInt(strItem))
End If
End Sub
error:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in HRTest.exe
Additional information: Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
It occurs when I attempt to add a new record. I've stripped out much
of the code, leaving the pertinent (I hope) info. I'm using MS Access
2003 as the database.
The error appears to be quite self-explanatary, but I've read about
the locktype an it seems correct. The "Current Recordset" I'm unsure
of. I just want to find out if the record is on file and if not, add
it, otherwise I'll update it.
Sounds simple, but I need help.
Thanks,
Hexman
---------------------------------------------------------------------------------------------------
Imports System.Data.OleDb
'
'
'
Public Class Form1
Inherits System.Windows.Forms.Form
'
'
'
Public db As ADODB.Connection
Public C As ADODB.Command
Public POrstData As ADODB.Recordset
Private Sub DoUpdate()
'make connection and open database
db = New ADODB.Connection
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & txtDatabaseDir & "HRMDB.MDB" &
";Persist Security Info=False"
db.Open()
C = New ADODB.Command
C.ActiveConnection = db
C.CommandType = ADODB.CommandTypeEnum.adCmdText
'create and open record set
POrstData = New ADODB.Recordset
POrstData.Open("PurOrd", db,
ADODB.CursorTypeEnum.adOpenkeyset,
ADODB.LockTypeEnum.adLockOptimistic, True)
End Sub
Private Sub UpdateProcess()
C.CommandText = "Select PODate, POLoc, POItem FROM PurOrd " & _
"where PODate = #" & SelectedDate & "# and POLoc = '" & strLoc & "' "
& _
"AND POItem = " & CInt(strItem)
POrstData = C.Execute
If POrstData.EOF = True Then
POrstData.AddNew() <======= Fails with Error =====
POrstData.Fields.Item("PODate").Value = "#" & strDate & "#"
POrstData.Fields.Item("POLoc").Value = strLoc
POrstData.Fields.Item("POItem").Value = CInt(strItem)
POrstData.Update()
Else
MsgBox("Record Found: #" & SelectedDate & "# " & strLoc & " "
& CInt(strItem))
End If
End Sub