List Info

Thread: Updating ADO records




Updating ADO records
user name
2006-12-12 23:05:57
To the Help Group,

I'm still attempting to work with ADO without the data
control.  I'm 
successrfully opening the connection and recordset, but when
I attempt to 
change, add, or update, I receive the following error
message:

     "Runtime Error 3251:
        Current recordset does not support updating.  This
may be a 
limitation of the Provider
        or the locktype."

I'm pasting the "Form_Load() langauge below:

     Private Sub Form_Load()

    conn.Open ("Provider = Microsoft.Jet.OLEDB.4.0;Data
Source =" & App.Path 
& "General
        Ledger.mdb")
   'set rsTrxno.Open = "SELECT * FROM Glact Order by
Acno" 
,adopendynamic,adlockoptimistic

   'Establishes RecordSource
   Set rsTrxno = conn.Execute("SELECT * FROM
Trxno", adLockOptimistic)
   Set rsGlact = conn.Execute("SELECT * FROM Glact
Order by Acno", 
adLockOptimistic)
   Set rsGltrx = conn.Execute("SELECT * FROM Gltrx
Order by Ref", 
adLockOptimistic)

I've tried numerous other combinations, but without success.
 I'm now 
working from two ADO books recently purchased and have
received a great deal 
of help from those sources.  However, neither of those nor
any of the 14 
others reference this partifular problem.  Can someone give
me an idea?

Don Gaither




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://grou
ps.yahoo.com/group/helpwithvb/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://
groups.yahoo.com/group/helpwithvb/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:helpwithvb-digest@yahoogroups.com 
    mailto:helpwithvb-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    helpwithvb-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 
Updating ADO records
user name
2006-12-12 23:20:16
Hi Don,

Explain a little more about what you need to do.

Like..., " I changed 3 field values, and 
now I want to place that new data into the Database."

Or...., the User has updated the fields by using
the form I created, but how do I get the new
data into the Recordset ?

Steve


From: helpwithvb@yahoogroups.com 
[mailto:helpwithvb@yahoogroups.com] On Behalf Of Donald
Gaither
Sent: Tuesday, December 12, 2006 6:06 PM
To: helpwithVB@yahoogroups.com
Subject: [helpwithvb] Updating ADO records

To the Help Group,

I'm still attempting to work with ADO without the data
control. I'm 
successfully opening the connection and Recordset, but when
I attempt to 
change, add, or update, I receive the following error
message:

"Runtime Error 3251:
Current Recordset does not support updating. This may be a 
limitation of the Provider
or the locktype."

I'm pasting the "Form_Load() langauge below:

Private Sub Form_Load()

conn.Open ("Provider = Microsoft.Jet.OLEDB.4.0;Data
Source =" & App.Path 
& "General
Ledger.mdb")
'set rsTrxno.Open = "SELECT * FROM Glact Order by
Acno" 
,adopendynamic,adlockoptimistic

'Establishes RecordSource
Set rsTrxno = conn.Execute("SELECT * FROM Trxno",
adLockOptimistic)
Set rsGlact = conn.Execute("SELECT * FROM Glact Order
by Acno", 
adLockOptimistic)
Set rsGltrx = conn.Execute("SELECT * FROM Gltrx Order
by Ref", 
adLockOptimistic)

I've tried numerous other combinations, but without success.
I'm now 
working from two ADO books recently purchased and have
received a great deal

of help from those sources. However, neither of those nor
any of the 14 
others reference this partifular problem. Can someone give
me an idea?

Don Gaither
.
.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://grou
ps.yahoo.com/group/helpwithvb/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://
groups.yahoo.com/group/helpwithvb/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:helpwithvb-digest@yahoogroups.com 
    mailto:helpwithvb-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    helpwithvb-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 
Updating ADO records
user name
2006-12-13 02:13:44

Don,

 

It’s somewhat hard to follow your code&#8230;it looks like your missing major chunks of the process.  Here’s a pretty well commented routine that illustrates the general principles of using ADO commands.

 

 

 

Private Sub Command1_Click()

  
'Define&nbsp;the ;three ;objects&nbsp;that&nbsp;we need,
 &nbsp;
' &nbsp; A&nbsp;Connection Object - connects to our&nbsp;data&nbsp;source
 &nbsp;
' &nbsp; A&nbsp;Command Object -&nbsp;defines what&nbsp;data&nbsp;to ;get from the data source
 &nbsp;
' &nbsp; A&nbsp;RecordSet Object - stores the&nbsp;data&nbsp;we ;get from our data source

  
Dim conConnection As New ADODB.Connection
 &nbsp;
Dim cmdCommand As New ADODB.Command
 &nbsp;
Dim rstRecordSet As New ADODB.Recordset


&nbsp; 
'Defines&nbsp;the&nbsp;connection string for the&nbsp;Connection. &nbsp;Here&nbsp;we ;have used fields
 &nbsp;
'Provider, Data&nbsp;Source and&nbsp;Mode&nbsp;to assign ;values&nbsp;to the properties
 &nbsp;
' conConnection.Provider&nbsp;and ;conConnection.Mode

  
conConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
 &nbsp; &nbsp;  
App.Path & "&quot; & "database.mdb;Mode=Read|Write"


&nbsp; 
'Define&nbsp;the ;location&nbsp;of ;the cursor engine,&nbsp;in this case we&nbsp;are&nbsp;opening&nbsp;an&nbsp;Access&nbsp;database
 &nbsp;
'and adUseClient is&nbsp;our ;only choice.

  
conConnection.CursorLocation = adUseClient


&nbsp; 
'Opens&nbsp;our connection&nbsp;using&nbsp;the&nbsp;password ";Admin"; to&nbsp;access&nbsp;the&nbsp;database. &nbsp;If there was no&nbsp;password
 &nbsp;
'protection on&nbsp;the&nbsp;database&nbsp;this&nbsp;field&nbsp;could&nbsp;be ;left out.

  
conConnection.Open


&nbsp; 
'Defines&nbsp;our&nbsp;command&nbsp;object

  
' .ActiveConnection tells the command to use&nbsp;our&nbsp;newly&nbsp;created&nbsp;command object.
 &nbsp;
' .CommandText&nbsp;tells&nbsp;the&nbsp;command&nbsp;how&nbsp;to get the data, in&nbsp;this&nbsp;case ;the command
 &nbsp;
' &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; will evaluate the text as&nbsp;an&nbsp;SQL string ;and we will return all
 &nbsp;
' &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; records from a table called tabTestTable
 &nbsp;
' .CommandType&nbsp;tells&nbsp;the&nbsp;command&nbsp;to ;evaluate&nbsp;the&nbsp;.CommandText property ;as an SQL&nbsp;string.

  
With cmdCommand
 &nbsp; &nbsp;.ActiveConnection = conConnection
 &nbsp; &nbsp;.CommandText = "SELECT *&nbsp;FROM&nbsp;tabTestTable;"
 &nbsp; &nbsp;.CommandType = adCmdText
 &nbsp;
End With

  
'Defines&nbsp;our&nbsp;RecordSet object.

  
' &nbsp;.CursorType sets a&nbsp;static&nbsp;cursor, the&nbsp;only&nbsp;choice&nbsp;for&nbsp;a client side cursor
 &nbsp;
' &nbsp;.CursorLocation&nbsp;sets ;a client side cursor, the only choice for an&nbsp;Access&nbsp;database
 &nbsp;
' &nbsp;.LockType sets an&nbsp;optimistic lock type
 &nbsp;
' &nbsp;.Open&nbsp;executes the&nbsp;cmdCommand object against ;the data source and stores the
 &nbsp;
' &nbsp; &nbsp; &nbsp;  returned records in our RecordSet object.

  
With rstRecordSet
 &nbsp; &nbsp;.CursorType = adOpenStatic
 &nbsp; &nbsp;.CursorLocation = adUseClient
 &nbsp; &nbsp;.LockType = adLockOptimistic
 &nbsp; &nbsp;.Open cmdCommand
 &nbsp;
End With

  
'Firstly&nbsp;test&nbsp;to see if any&nbsp;records have&nbsp;been&nbsp;returned, if&nbsp;some&nbsp;have&nbsp;been&nbsp;returned&nbsp;then
 &nbsp;
'the .EOF property&nbsp;of the RecordSet ;will be false, if none&nbsp;have&nbsp;been&nbsp;returned then&nbsp;the
 &nbsp;
'property&nbsp;will&nbsp;be ;true.

  
If rstRecordSet.EOF = False Then

   
'Move ;to the first record

   
rstRecordSet.MoveFirst

   
'Lets ;move through&nbsp;the records&nbsp;one at a&nbsp;time&nbsp;until&nbsp;we reach the last record
 &nbsp; &nbsp;
'and print out the values of&nbsp;each&nbsp;field

   
Do

   ; &nbsp; 
'Access&nbsp;the ;field ;values&nbsp;using&nbsp;the fields ;collection and&nbsp;print&nbsp;them&nbsp;to a message box.
 &nbsp; &nbsp;  
'In this case I&nbsp;do ;not know what you might call&nbsp;the&nbsp;columns&nbsp;in&nbsp;your ;database&nbsp;so ;this
 &nbsp; &nbsp;  
'is the safest way to&nbsp;do ;it. &nbsp;If&nbsp;I did know the&nbsp;names&nbsp;of ;the columns ;in your table
 &nbsp; &nbsp;  
'and they were called &quot;Column1"&nbsp;and "Column2"&nbsp;I could reference&nbsp;their&nbsp;values&nbsp;using:

   ; &nbsp; 
' &nbsp;rstRecordSet!Column1
 &nbsp; &nbsp;  
' &nbsp;rstRecordSet!Column2


&nbsp; &nbsp; &nbsp; 
MsgBox "Record &quot; & rstRecordSet.AbsolutePosition & "&nbsp;" & _
 &nbsp; &nbsp;   ; &nbsp; 
rstRecordSet.Fields(0).Name & "=&quot; & rstRecordSet.Fields(0& "&nbsp;" & _
 &nbsp; &nbsp;   ; &nbsp; 
rstRecordSet.Fields(1).Name & "=&quot; & rstRecordSet.Fields(1)

   ; &nbsp; 
'Move ;to the next record

   ; &nbsp; 
rstRecordSet.MoveNext
 &nbsp; &nbsp;
Loop Until rstRecordSet.EOF = True

   
'Add a new&nbsp;record

   
With rstRecordSet
 &nbsp; &nbsp; &nbsp;.AddNew
 &nbsp; &nbsp; &nbsp;.Fields(0) = "New&quot;
 &nbsp; &nbsp; &nbsp;.Fields(1) = "Record"
 &nbsp; &nbsp; &nbsp;.Update
 &nbsp; &nbsp;
End With

   
'Move ;back to the first record and&nbsp;delete it

   
rstRecordSet.MoveFirst
 &nbsp; &nbsp;
rstRecordSet.Delete
 &nbsp; &nbsp;
rstRecordSet.Update


&nbsp; &nbsp; 
'Close&nbsp;the recordset

   
rstRecordSet.Close
 &nbsp;
Else
 &nbsp; &nbsp;
MsgBox "No&nbsp;records were&nbsp;returned using the query "; & cmdCommand.CommandText
 &nbsp;
End If

  
'Close&nbsp;the connection

  
conConnection.Close

  
'Release&nbsp;your&nbsp;variable references

  
Set conConnection = Nothing
 &nbsp;
Set cmdCommand = Nothing
 &nbsp;
Set rstRecordSet = Nothing
End Sub

 


From: helpwithvb@yahoogroups.com [mailto:helpwithvb@yahoogroups.com] On Behalf Of Donald Gaither
Sent: Tuesday, December 12, 2006 6:06 PM
To: helpwithVB@yahoogroups.com
Subject: [helpwithvb] Updating ADO records

 

To the Help Group,

I'm still attempting to work with ADO without the data control. I'm
successrfully opening the connection and recordset, but when I attempt to
change, add, or update, I receive the following error message:

"Runtime Error 3251:
Current recordset does not support updating. This may be a
limitation of the Provider
or the locktype.&quot;

I'm pasting the "Form_Load() langauge below:

Private Sub Form_Load()

conn.Open ("Provider = Microsoft.Jet.OLEDB.4.0;Data Source =&quot; & App.Path
& "General
Ledger.mdb")
'set rsTrxno.Open = "SELECT * FROM Glact Order by Acno"
,adopendynamic,adlockoptimistic

'Establishes RecordSource
Set rsTrxno = conn.Execute("SELECT * FROM Trxno";, adLockOptimistic)
Set rsGlact = conn.Execute("SELECT * FROM Glact Order by Acno",
adLockOptimistic)
Set rsGltrx = conn.Execute("SELECT * FROM Gltrx Order by Ref",
adLockOptimistic)

I've tried numerous other combinations, but without success. I'm now
working from two ADO books recently purchased and have received a great deal
of help from those sources. However, neither of those nor any of the 14
others reference this partifular problem. Can someone give me an idea?

Don Gaither

__._,_.___ __,_._,___
Updating ADO records
user name
2006-12-13 00:11:06
Hey Don,

Maybe I misunderstood what you are trying to do.

Look at this web page, and the other web pages
that it has links to.  All very basic ADO stuff.

http://w
ww.vb-helper.com/AdoTalk/AdoTalk.htm

..and this page shows how to update the Recordset:

http://www
.vb-helper.com/AdoTalk/Ado2b.htm

To be honest, that will probably not make much
sense because the code is taken out of its context.

Might be better to download the entire sample
program / project  and look through it to see
how all of the pieces work together.

Then when you start to ask other questions, but
now your code uses the Bang ( ! ) Operator
we can yell at you for that < g >

adoRS!SomeField = 42&

is another way to write...

adoRS.Fields(FieldName).Value = 42&


In my previous e-mail I mention a situation where
by way of your form the User has supplied all of
the needed data ( filled in all fields )
for a new record.

Now we need to put that new record 
into the database table:

http:/
/www.vb-helper.com/howto_ado_insert.html


Remember to look at the Recordset as just 
another array type, or another large
tractor trailer going down the highway.

The Recordset is just a transportation vehicle
when viewed in its simplest form.

All The Best,
Steve

7:10  PM  EST  Tuesday, December 12, 2006
.
.

From: helpwithvb@yahoogroups.com 
[mailto:helpwithvb@yahoogroups.com] On Behalf Of Donald
Gaither
Sent: Tuesday, December 12, 2006 6:06 PM
To: helpwithVB@yahoogroups.com
Subject: [helpwithvb] Updating ADO records

To the Help Group,

I'm still attempting to work with ADO without the data
control. I'm 
successrfully opening the connection and recordset, but when
I attempt to 
change, add, or update, I receive the following error
message:

"Runtime Error 3251:
Current recordset does not support updating. This may be a 
limitation of the Provider
or the locktype."

I'm pasting the "Form_Load() langauge below:

Private Sub Form_Load()

conn.Open ("Provider = Microsoft.Jet.OLEDB.4.0;Data
Source =" & App.Path 
& "General
Ledger.mdb")
'set rsTrxno.Open = "SELECT * FROM Glact Order by
Acno" 
,adopendynamic,adlockoptimistic

'Establishes RecordSource
Set rsTrxno = conn.Execute("SELECT * FROM Trxno",
adLockOptimistic)
Set rsGlact = conn.Execute("SELECT * FROM Glact Order
by Acno", 
adLockOptimistic)
Set rsGltrx = conn.Execute("SELECT * FROM Gltrx Order
by Ref", 
adLockOptimistic)

I've tried numerous other combinations, but without success.
I'm now 
working from two ADO books recently purchased and have
received a great deal

of help from those sources. However, neither of those nor
any of the 14 
others reference this partifular problem. Can someone give
me an idea?

Don Gaither
. 


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://grou
ps.yahoo.com/group/helpwithvb/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://
groups.yahoo.com/group/helpwithvb/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:helpwithvb-digest@yahoogroups.com 
    mailto:helpwithvb-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    helpwithvb-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )