Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting record to edit using ADO

I am using ADO to edit data in a SQL database.

My problem is how to select a record.

Using "Find" on the recordset works, but takes several minutes.

Using "Excecute" on the connection to run a SQL query only takes seconds
(thanks Tom!), but then the recordset is not editable.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Selecting record to edit using ADO

Use a different cursor type. The default cursor is read-only.

Or show some code...

Tim


"Ken Valenti" wrote in message
...
I am using ADO to edit data in a SQL database.

My problem is how to select a record.

Using "Find" on the recordset works, but takes several minutes.

Using "Excecute" on the connection to run a SQL query only takes seconds
(thanks Tom!), but then the recordset is not editable.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting record to edit using ADO

Here's the code.
This finds the record, but is read-only.

Sub ModifyRecord()
Set TheCN = New ADODB.Connection
TheCN.Open TheConnectionString
Set TheRS = TheCN.Execute(SQL_String)
TheRS.Fields(7).Value = "New Value"
TheRS.Update
CloseConnections
End Sub


"Tim Williams" wrote:

Use a different cursor type. The default cursor is read-only.

Or show some code...

Tim


"Ken Valenti" wrote in message
...
I am using ADO to edit data in a SQL database.

My problem is how to select a record.

Using "Find" on the recordset works, but takes several minutes.

Using "Excecute" on the connection to run a SQL query only takes seconds
(thanks Tom!), but then the recordset is not editable.





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Selecting record to edit using ADO

Try something like;

Public Sub testwrite()
Dim cnn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim strSQL1 As String, strConn
Dim i As Integer
i = 1

'Use for Access (jet)
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Program Files\Microsoft Office\" _
& "OFFICE11\SAMPLES\Northwind.mdb;Persist Security Info=False"

'Use for SQL server (OLEDB)
strConn = "Provider=SQLOLEDB.1;" _
& "Integrated Security=SSPI;" _
& "Persist Security Info=False;" _
& "Initial Catalog=Northwind;" _
& "Data Source=PE1600"


strSQL1 = "SELECT LastName, FirstName " _
& "FROM Employees; "
Set cnn = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cnn.Open strConn
rs1.Open strSQL1, cnn, adOpenDynamic, adLockOptimistic
For i = 1 To 3
rs1.AddNew
rs1!LastName = Sheets("Sheet1").Range("A" & i)
rs1!FirstName = Sheets("Sheet1").Range("B" & i)
i = i + 1
rs1.Update
Next
rs1.Close
cnn.Close
End Sub

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Ken Valenti" wrote:
| Here's the code.
| This finds the record, but is read-only.
|
| Sub ModifyRecord()
| Set TheCN = New ADODB.Connection
| TheCN.Open TheConnectionString
| Set TheRS = TheCN.Execute(SQL_String)
| TheRS.Fields(7).Value = "New Value"
| TheRS.Update
| CloseConnections
| End Sub


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting record to edit using ADO

Thanks - works now!

"Dave Patrick" wrote:

Try something like;

Public Sub testwrite()
Dim cnn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim strSQL1 As String, strConn
Dim i As Integer
i = 1

'Use for Access (jet)
'strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Program Files\Microsoft Office\" _
& "OFFICE11\SAMPLES\Northwind.mdb;Persist Security Info=False"

'Use for SQL server (OLEDB)
strConn = "Provider=SQLOLEDB.1;" _
& "Integrated Security=SSPI;" _
& "Persist Security Info=False;" _
& "Initial Catalog=Northwind;" _
& "Data Source=PE1600"


strSQL1 = "SELECT LastName, FirstName " _
& "FROM Employees; "
Set cnn = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cnn.Open strConn
rs1.Open strSQL1, cnn, adOpenDynamic, adLockOptimistic
For i = 1 To 3
rs1.AddNew
rs1!LastName = Sheets("Sheet1").Range("A" & i)
rs1!FirstName = Sheets("Sheet1").Range("B" & i)
i = i + 1
rs1.Update
Next
rs1.Close
cnn.Close
End Sub

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Ken Valenti" wrote:
| Here's the code.
| This finds the record, but is read-only.
|
| Sub ModifyRecord()
| Set TheCN = New ADODB.Connection
| TheCN.Open TheConnectionString
| Set TheRS = TheCN.Execute(SQL_String)
| TheRS.Fields(7).Value = "New Value"
| TheRS.Update
| CloseConnections
| End Sub





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Selecting record to edit using ADO

Glad to hear it. You're welcome.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Ken Valenti" wrote:
| Thanks - works now!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Selecting record to edit using ADO

See the notes for LockType

http://msdn.microsoft.com/archive/de...gramming. asp

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Ken Valenti" wrote:
|I am using ADO to edit data in a SQL database.
|
| My problem is how to select a record.
|
| Using "Find" on the recordset works, but takes several minutes.
|
| Using "Excecute" on the connection to run a SQL query only takes seconds
| (thanks Tom!), but then the recordset is not editable.
|
|


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting the latest record for transactions ahmedzia Excel Discussion (Misc queries) 4 September 2nd 09 02:36 PM
Selecting Last Record NWO Excel Discussion (Misc queries) 5 October 9th 08 02:41 AM
edit a record like 17.00 gbp so it becomes 17.00 using a formula John Excel Discussion (Misc queries) 2 January 17th 06 02:23 PM
how do I edit a record in database Ashu Excel Programming 2 September 27th 05 02:04 PM
Cannot Record a Macro or Edit VBA Marc Excel Programming 1 February 11th 04 08:25 PM


All times are GMT +1. The time now is 03:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"