Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert into Access Table

Status
Not open for further replies.

wsexton

Technical User
Dec 4, 2001
49
0
0
US
I'm using perl to insert data from a file into an MS Access database. I'd like to use the autonumber feature in Access. I can change the autonumber field to a number field and insert a number I create. How do I insert a record and allow Access to assign an autonumber?

Here's my current code:

$dbh = DBI->connect('dbi:ODBC:DSU Requestor DB')|| die print ("Cannot connect to the database");;

$sqlstmt = "INSERT INTO request_data VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

my $sth = $dbh->prepare($sqlstmt);

open DATA, "testdata.txt";

while (<DATA>) {
my @coldata = split(":", $_);
$sth->execute(@coldata);
}

This only works if I don't use the autonumber feature. Any suggestions would be appreciated.
 
Because it's an auto increment feature, you don't need to post a varaible for this, but you will need to specify all other fields in your insert statement
Code:
$sqlstmt = "INSERT INTO request_data (name, address, ...) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
HTH
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top