Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004

    Unanswered: Help Required to insert Data into the Databse Table

    I am new to the Perl programming
    I am facing a problem with insertig the Data in the Database Table.I am using the MS ACCESS
    I am able to retrieve the Data from the Databse Table but when it come to insertions I am not able to do so.
    plz help me.
    This is the code which I am trying to execute.I am not getting any error but the Data is not coming to the Table
    This is the subroutine for connecting to the Database.
    ================================================== ================================================== ================
    sub connectDB(){
    $DSN = "MEXP";
    $db = Win32::ODBC->new($DSN);

    if (!$db) {
    print "Failed to connect to Database";
    #print "Got Connected\n\n";
    print "\n";
    ================================================== ================================================== ================

    I have written this subroutine for Time
    sub Time(){
    my($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time);
    $Year = 2 .$Year-100;
    $Time = ("$Hour:$Minute:$Second");
    $Date = ("$Day-$Month-$Year");
    ================================================== ================================================== =============
    print "Enter Your Name:- ";
    chomp(my $Name = <STDIN>);
    print "Enter The Amount:-";
    chomp(my $Amount = <STDIN>);
    print "Enter The Description:-";
    chomp(my $Description = <STDIN>);
    my $query = "INSERT INTO MONTHLY(Name,Time,Date,Amount,Description)";
    $query .= "VALUES ($Name,$Time,$Date,$Amount,$Description)";
    print "\n";
    my $Insert_Record = $db->sql($query)|| die "Fetch Error: ",$db->Error();
    print $Insert_Record;
    print "Your Expense has been logged!";

    please help me here ASAP


  2. #2
    Join Date
    Mar 2004
    It's certainly because of the simple quote and double quote necessary ton INSERT.

    Try to use DBI instead of Win32::ODBC. With DBI, you got a method named quote() that you apply to a char or varchar value. It prepares the string to the insertion in table (with simple quote).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts