Re: How To Return Record Number From AddNew



Jeff Gaines wrote:
On 27/08/2007 in message <ecOJhlJ6HHA.5160@xxxxxxxxxxxxxxxxxxxx> Bob
Barrows [MVP] wrote:

My pesonal recommendation: don't use a recordset for data
maintenance. Instead, use SQL DML (INSERT, UPDATE and DELETE)
statements, wither encapsulated in saved parameter queries (stored
procedures) or parameterized with parameter markers. This will allow
you to execute the SELECT @@identity statement to retrieve the new
autonumber.

Many thanks, Bob :-)
The links are particularly helpful, and they led to other links and
so on...

I am struggling to find which version of MSJet I have. There are
jet500.dll, msjet35.dll and msjet40.dll on the system. I use Access
97 and the connections string is:

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
strConnection += m_DBPath;
strConnection += ";";

Since this works then presumably I have version 4?

No, but it's backward-compatible in my experience. I have read some
admonitions here and there against using the 4.0 driver against an A97
(Jet 3.51) database, but I have never run into any issues.


I am trying to add "SELECT @@IDENTITY" to the connection string but it
falls over with that.

It cannot be added to the connection string. You have to use it as the
source of a recordset: it's a SQL Select statement.

My real problem at the moment is:

If I use adRS("0") I get the error 'adRS' is a 'variable' but is used
like a 'method'

How did you try to use it?
Is the name of the field "0"? You never showed us the select statement
used to open the recordset, so I have no idea what the names of the
fields in the recordset are. Of course, using the field names is
inefficient compared to using the ordinal positions of the fields to
refer to them. I don't do C# so you will need to translate this, but If
you are trying to see the value of the first field in the recordset you
would do this:

valuoffirstfield=adRS(0).value

If I use adRS["RecordNumber"] I get the error Cannot apply indexing
with [] to an expression of type 'ADODB.Recordset'

What is the name of your autonumber field?


All the examples I have found are VB/VBScript, usually you can replace
round brackets with square ones for C but apparently not here!

Better to ask about this in a C# newsgroup.

PS. Why are you using classic ADO in a .Net application? You should be
using ADO.Net. You should post ADO.Net questions to this group:
microsoft.public.dotnet.framework.adonet

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


.



Relevant Pages

  • Re: Access sending data to Word VBA Userform
    ... To get assistance on that, it would be best to ask in an Access newsgroup, ... Doug Robbins - Word MVP ... Dim rs As DAO.Recordset ... ' Set the number of Columns = number of Fields in recordset ...
    (microsoft.public.word.vba.userforms)
  • Re: Recordset used in Select/Option pick list
    ... Bob Barrows [MVP] wrote: ... to the list of options generated from your recordset. ... What the getstring is doing is constructing a string from all the ... Please reply to the newsgroup. ...
    (microsoft.public.data.ado)
  • Re: Copying Binary data from one table to another
    ... data from the recordset and AppendChunk to put the binary data into the ... Microsoft MVP -- ASP/ASP.NET ... Please reply to the newsgroup. ...
    (microsoft.public.inetserver.asp.db)
  • Re: Median calculation
    ... Already answered in another newsgroup to which you posted the same question. ... Dim rs As DAO.Recordset ... 'Open a recordset on the table. ... DMedian = rs ...
    (microsoft.public.access.queries)
  • Re: Binding Data to Forms, Textboxes etc.
    ... I intended to post this to the .net forms newsgroup, and yes I may be mixing ... > Windows applications are a very different animal to Access forms. ... The terms 'Row Source' and 'Recordset' are not used ... >> "A bound form means that you have identified a Row Source for your form. ...
    (microsoft.public.access.formscoding)