We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

ASP Locktype error help

Chris Jones
Chris Jones asked
on
Medium Priority
441 Views
Last Modified: 2012-05-06
hello

i have a small application and i get this error when i try to add a record


Additional information: Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.
Comment
Watch Question

Top Expert 2009

Commented:
Chris JonesLead Application Web Developer

Author

Commented:
i dont quite understand the links you posted here is my code maybe this will help
        If ErrorMessage.Text = "" Then
            Call localDBConnectionOpen()
            sqlstmt = "SELECT * FROM Alumni WHERE ID = '" & ID & "' "
            rs = DBRecordSetNewFast(ConnPortal, sqlstmt)
 
            If rs.EOF Then
                rs.AddNew()
                Call DBFieldUpdate(rs, "Name", NewName)
                Call DBFieldUpdate(rs, "Email", NewEmail)
                Call DBFieldUpdate(rs, "Phone", NewPhone)
                Call DBFieldUpdate(rs, "Address", NewAddress)
 
                rs.Update()
                ErrorMessage.Text = "Adloc acct '" & ID & " " & ID & "' added."
            Else
                ErrorMessage.Text = "    Adloc acct '" & ID & " already exists."
            End If
            rs = DBRecordSetDestroy(rs)
            Call localDBConnectionClose()
        End If

Open in new window

Chris JonesLead Application Web Developer

Author

Commented:
here is my function with my locktype info in it
    Public Function DBRecordSetNew(ByRef conn As ADODB.Connection, ByRef sqlstmt As String) As Object
        Dim newrs As ADODB.Recordset
 
        newrs = New ADODB.Recordset
        newrs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        newrs.CursorLocation = ADODB.CursorLocationEnum.adUseServer
        DBDebugStartTime = DBGetTickCount()
        'Try
        DBAbortSqlStmt = sqlstmt
        DBAbortConn = conn.ConnectionString
        newrs.Open(sqlstmt, conn, , ADODB.LockTypeEnum.adLockOptimistic)
        'Catch ex As Exception
        '    DBException = ex.Message & " " & ex.Source & " " & ex.ToString
        'End Try
        DBRecordSetNew = newrs
        Call DBDebugLogSQL("New", sqlstmt)
    End Function

Open in new window

Chris JonesLead Application Web Developer

Author

Commented:
Hello are you still avalable nmarun:
Top Expert 2009

Commented:
Yes, I am.. just caught with other things.

Have a look at this:
http://msdn.microsoft.com/en-us/library/ms680885(VS.85).aspx

and/or try the code below.

rsGuruData.AddNew
rsGuruData.Fields("FirstName") = strFirstName
rsGuruData.Fields("LastName") = strLastName
rsGuruData.Fields("Age") = intAge
rsGuruData.Update

Open in new window

Chris JonesLead Application Web Developer

Author

Commented:
Hmm were do i post this it tells me its not declared
Top Expert 2009

Commented:

      If ErrorMessage.Text = "" Then
            Call localDBConnectionOpen()
            sqlstmt = "SELECT * FROM Alumni WHERE ID = '" & ID & "' "
            rs = DBRecordSetNewFast(ConnPortal, sqlstmt)
 
            If rs.EOF Then
                rs.AddNew()
                rs.Fields("Name") = NewName
                rs.Fields("Email") = NewEmail
                rs.Fields("Phone") = NewPhone
                rs.Fields("Address") = NewAddress
                rs.Update()
                ErrorMessage.Text = "Adloc acct '" & ID & " " & ID & "' added."
            Else
                ErrorMessage.Text = "    Adloc acct '" & ID & " already exists."
            End If
            rs = DBRecordSetDestroy(rs)
            Call localDBConnectionClose()
        End If

Open in new window

Chris JonesLead Application Web Developer

Author

Commented:
i get an error when i replace it here

                rs.Fields("Name") = NewName
                rs.Fields("Email") = NewEmail
                rs.Fields("Phone") = NewPhone
                rs.Fields("Address") = NewAddress

new code
rsGuruData.AddNew
                rsGuruData.Fields("Name") = NewName
                rsGuruData.Fields("Email") = NewEmail
                rsGuruData.Fields("Phone") = NewPhone
                rsGuruData.Fields("Address") = NewAddress
rsGuruData.Update

ERROR

not defined
rsGuruData
Chris JonesLead Application Web Developer

Author

Commented:
the database is not geting updated is there any reason why ?
Top Expert 2009

Commented:
I'm not sure why you are using that code when I posted the actual code for you:

      If ErrorMessage.Text = "" Then
            Call localDBConnectionOpen()
            sqlstmt = "SELECT * FROM Alumni WHERE ID = '" & ID & "' "
            rs = DBRecordSetNewFast(ConnPortal, sqlstmt)
 
            If rs.EOF Then
                rs.AddNew()
                rs.Fields("Name") = NewName
                rs.Fields("Email") = NewEmail
                rs.Fields("Phone") = NewPhone
                rs.Fields("Address") = NewAddress
                rs.Update()
                ErrorMessage.Text = "Adloc acct '" & ID & " " & ID & "' added."
            Else
                ErrorMessage.Text = "    Adloc acct '" & ID & " already exists."
            End If
            rs = DBRecordSetDestroy(rs)
            Call localDBConnectionClose()
        End If

Open in new window

Chris JonesLead Application Web Developer

Author

Commented:
i get this error when i use the code posted above

Error      3      Property 'Item' is 'ReadOnly'.
Chris JonesLead Application Web Developer

Author

Commented:
this code produces no error but does not update the database
       If ErrorMessage.Text = "" Then
            Call localDBConnectionOpen()
            sqlstmt = "SELECT * FROM Alumni WHERE ID = '" & ID & "' "
            rs = DBRecordSetNewFast(ConnPortal, sqlstmt)
 
            If rs.EOF Then
                rs.AddNew()
                Call DBFieldUpdate(rs, "Name", NewName)
                Call DBFieldUpdate(rs, "Email", NewEmail)
                Call DBFieldUpdate(rs, "Phone", NewPhone)
                Call DBFieldUpdate(rs, "Address", NewAddress)
 
                rs.Update()
                ErrorMessage.Text = "Adloc acct '" & ID & " " & ID & "' added."
            Else
                ErrorMessage.Text = "    Adloc acct '" & ID & " already exists."
            End If
            rs = DBRecordSetDestroy(rs)
            Call localDBConnectionClose()
        End If

Open in new window

Top Expert 2009

Commented:
Firstly, what does DBFieldUpdate do? I'm not sure of its implementation. I'm not saying its wrong, but just that I'm not sure. You can directly say:
rs.Fields("Name") = NewName

Also, where does 'NewName' get its value from? I also do not see some line like:

NewName = 'some place where the new value comes from'.

Chris JonesLead Application Web Developer

Author

Commented:
do you want me to display the code  it may be a lot

also sorry for the long delay have been out of town with no computer
Top Expert 2009

Commented:
What datatype is rs?

rs = DBRecordSetNewFast(ConnPortal, sqlstmt)


Chris JonesLead Application Web Developer

Author

Commented:
it calls a function tht reads each field  of the database from my SQL selection statment
Top Expert 2009

Commented:
My question was what 'rs' was and not what DBRecordSetNewFast does.
Chris JonesLead Application Web Developer

Author

Commented:
recordset is the ADODB connection that traverses through the records.sorry for the long delay i have had a computer meltdown but everythings fixed and i will be happy to continue reciveing the help for you
Top Expert 2009
Commented:
blingtec, please have a look at the link below. There's an example that you can use:
http://msdn.microsoft.com/en-us/library/ms677536(VS.85).aspx

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Chris JonesLead Application Web Developer

Author

Commented:
function from the file that yu requested


    Public Function DBRecordSetNewFast(ByRef conn As ADODB.Connection, ByRef sqlstmt As String) As Object
        Dim newrs As ADODB.Recordset
 
        newrs = New ADODB.Recordset
        newrs.CursorType = ADODB.CursorTypeEnum.adOpenForwardOnly
        newrs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        DBDebugStartTime = DBGetTickCount()
        'Try
        DBAbortSqlStmt = sqlstmt
        DBAbortConn = conn.ConnectionString
        newrs.Open(sqlstmt, conn)
        'Catch ex As Exception
        'DBException = ex.Message
        'End Try
        DBRecordSetNewFast = newrs
        Call DBDebugLogSQL("NewFast", sqlstmt)
    End Function

Open in new window

Top Expert 2009

Commented:
blingtec, this is seeming to go way out of control. Is it imperative that you use ADODB for this project? If not, you can quite easily do all this with ADO.NET classes like SqlCommand, DataSet and DataReader. There are tons of articles online for you to achieve this.
Chris JonesLead Application Web Developer

Author

Commented:
forced to close this question without an answer or account will be closed
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.