Solved

ADO Recordset Updates ?

Posted on 2010-09-15
4
205 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SqlDependency to get update from sql to my c# app 2 41
Regular expression help 2 25
Help with preventing downloading a zip file 10 37
Convert datetime to time string 10 21
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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