Greetings, I am trying to insert records into an MS Access 2K database. I am having problems with a table that has a primary key with the data type of "AutoNumber" which is a Access-driven auto-sequenced key. What I want is to pass along the fields and have Access or the ODBC driver generate the next sequence number.

I have tried leaving the field out, in which I get the "Too few parameters" error. I've tried an blank variable, which gives me a "Data Type mismatch" error. Also, I've tried the number 0, which will write a record where the sequential key is 0, but of course if I try to write another record, I get a duplicate key error. The table looks like:

order <--- table name ------- seq <--- primary key, autonumber item desc qty date_time user
Here's my test code:
# Make Database connection $db = new Win32::ODBC("DSN=$DATA_SOURCE_NAME; UID=$USER_ID;PWD=$PASSWORD;") or die Win32::ODBC::Error(); # Test Variables $new_item = "Test"; $new_desc = "Test description"; $new_qty = 2099; $new_user = "TESTUSER"; # get current time $now_time = gmtime; $new_seq = 0; # Insert row into database if ($db->Sql("INSERT INTO order VALUES ($new_seq,'$new_item', '$new_desc', $new_qty,'$now +_time','$new_user')" )) { # Print out any ODBC/SQL error print $db->Error(); } # Close the database $db->Close();
Has anyone had experience in doing this? Any help will be much appreciated. thanks.

In reply to Win32::ODBC insert question by thefid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.