Based on the help I had with a question last week, heres how to get the last insert ID from an access database using the recordset. This is Windows only.
If you are ever unfortunate enough to have to use Access then this should help you no end (it has for me :P)
use Win32::OLE;
use constant adOpenKeySet => 1;
use constant adLockPessimistic => 2;
use constant adCmdTable => '&H0002';
my $db_connection = new Win32::OLE('ADODB.Connection');
# Set the database connection details
my $db_datasource = 'Driver={Microsoft Access Driver (*.mdb)};
+';
$db_datasource .= 'DBQ=classifieds.mdb';
# Connect to the database and tie the recordset object to the
+database.
$db_connection->Open($db_datasource);
my $rs = new Win32::OLE("ADODB.Recordset");
# you're going to have to define your consts that
# you're using in the vbscript example
$rs->Open('ADS', $db_connection, adOpenKeySet, adLockPessimist
+ic, adCmdTable);
$rs->AddNew();
$rs->{'title'}{'Value'} = 'Ad title';
$rs->{'posted_by'}{'Value'} = 'Simon Proctor';
$rs->{'date_authorised'}{'Value'} = 0;
$rs->Update();
my $last_id = $rs->{'ID'}{'Value'};
$rs->close();
$db_connection->close();
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|