Solved

ADO Recordset Updates ?

Posted on 2010-09-15
4
200 Views
Last Modified: 2012-10-14
I have an ADO recordset, and here is how I set it up:
Dim oConnection As New ADODB.Connection
Dim oRecordset As New ADODB.Recordset
sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
oConnection.Open(sConnectString)
oRecordset.Open(sSQL, oConnection, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)

oRecordset.AddNew()
Orecordset.Fields("Name").value = "xxxxx"
Orecordset.Update

Now here I would like to get the value of the key that is created

x = oRecordSet.Field("ListID").value

But oRecordSet.Field("ListID").value returns Nothing.
If I break here and I query it I will find that the ListID does have a value.

How can i have this oRecordset show me the value of ListID ?
0
Comment
Question by:Jess31
  • 2
4 Comments
 
LVL 17

Expert Comment

by:Zhaolai
ID: 33688401
Try this:
Change tblName to your table name.

        Dim strSQL As String = "SET NOCOUNT ON INSERT INTO tblName(Name) VALUES('xxxxx') SELECT @@IDENTITY AS NewID SET NOCOUNT OFF"

        oConnection.Open(sConnectString)

        oRecordset = oConnection.Execute(strSQL)

        Dim varNewID As Integer = oRecordset("NewID").Value

        oConnection.Close()

Open in new window

0
 

Author Comment

by:Jess31
ID: 33688489
Zhaolai
When it hits the Execute(strSQL) I get this error

[QODBC] Expected lexical element not found: CREATE, DELETE, DROP, INSERT, SELECT, SP_BATCHCLEAR, SP_BATCHSTART, SP_BATCHUPDATE, SP_CATEGORIES, SP_CATEGORYTABLES, SP_CATEGORYREPORTS, SP_CLEARLASTINSERTID, SP_COLUMNS, SP_FOREIGNKEYS, SP_FQSAVETOCACHEROLLBACK, SP_LASTINSERTID, SP_LASTINSERTIDRETURN, SP_OPTIMIZEFULLSYNC, SP_OPTIMIZEUPDATESYNC, SP_PARAMETERS, SP_PRIMARYKEYS, SP_QBFILENAME, SP_REPORT, SP_REPORTCOLUMNS, SP_REPORTS, SP_SPECIALCOLUMNS, SP_STATISTICS, SP_TABLES, SP_VOID or UPDATE
0
 
LVL 10

Accepted Solution

by:
joriszwaenepoel earned 500 total points
ID: 33688985
Have a look at the following article:

HOW TO: Retrieve the Identity Value While Inserting Records into Access Database By Using Visual Basic .NET
http://support.microsoft.com/kb/815629

0
 

Author Comment

by:Jess31
ID: 33693041
These all seem quite laborious since in MS Access when connecting to SQL Server I was able to just read the key right after the recordset.Update. Maybe this has something do with with this driver/database which is different... I do know that this key is not a numeric. But it for sure does get produced as soon as I do the .Update cause I am able to retrieve it by calling another function that will query that record, but this is slow and I'm doing many records so I would like to avoid that.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now