Your almost there but, there is a problem with your SQL statement (it is not valid). The statement should be something like:
my $sqlstatement=("UPDATE servers SET nicl_driver_version = '$driver' +WHERE '$field1' = '$servlist'");
So you need to put single quotes around $driver as it is not all numeric, nor the SQL keyword NULL, I have also changed you WHERE clause to reflect what I think you want it to do. One good resource for SQL syntax is w3schools

you also don't appear to be using $field2 or $vals for anything, and don't need the use Win32::ODBC; line for anything as well (you are not using that module in your code at all).

One last thing is that you might want to prepare your SQL statement outside your loop, and then execute it on the inside, so you don't have to prepare the same statement time and time again unnecessarily). So your code might look something like this(untested):

use DBI; use strict; my $DSN='Database'; my $field1 = 'Server'; my $dbh=DBI->connect("dbi:ODBC:$DSN", "admin", "") or die "$DBI::errstr\n"; my $sth = $dbh->prepare( "UPDATE Servers SET nic1_driver_version= ? WHERE '$field1' = ?" ); #Open file for reading open(INPUT,"file.txt") || die; while (<INPUT>) { chomp; my ($servlist, $driver)=split(/,/); $sth->execute($driver,$servlist) or die; } close (INPUT); $dbh->disconnect;
update:added line to script because I neglected to initialize $field1 (so that line is now there), which would be the reason for the failure, p01p0t was having in Re: Re: Re: Re: Updating Specific Fields in MS Access

-enlil


In reply to Re: Re: Re: Updating Specific Fields in MS Access by Enlil
in thread Updating Specific Fields in MS Access by Anonymous Monk

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.