#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; my $dbh = DBI->connect('dbi:ODBC:DSN=SqlExpress;UID=USER;PWD=pass;Regi +onal=No;') or die "Can't connect: $!"; $dbh->{'LongReadLen'} = 40000; my $sql = 'SELECT crcp_cod_grupo, crcp_cod_prato FROM REST.dbo.CRCP_PR +ATO WHERE crcp_cod_grupo = "E"'; my $sth = $dbh->prepare($sql); $sth->execute(1, 10); while (my @row = $sth->fetchrow_array) { print "Grupo: $row[0] Prato: $row[1]\n"; } $sth->execute(12, 17); while (my $row = $sth->fetchrow_hashref) { print "Grupo: $row->{crcp_cod_grupo} Prato: $row->{crcp_cod_prato} +\n"; } $dbh->disconnect;

Hi there, I'm a newbie in Perl... this is my first attempt ever...I'm getting an error when I run the piece of code above (copied from an example somewhere on the net): DBD::ODBC::st execute failed: called with 2 bind variables when 0 are needed at query02.pl line 14. DBD::ODBC::st fetchrow_array failed: no select statement currently executing (SQ L-HY000) at query02.pl line 15. DBD::ODBC::st execute failed: called with 2 bind variables when 0 are needed at query02.pl line 19. Describe failed during DBI::st=HASH(0x1bfc3b4)->FETCH(NAME,0) at query02.pl line 20. DBD::ODBC::st fetchrow_hashref failed: no select statement currently executing ( SQL-HY000) at query02.pl line 20. Press any key to continue . . . I'm using Microsoft SQL Server Express Can anyone help me, please.. Thanks!!


In reply to execute failed: called with 2 bind variables when 0 are needed by perloz

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.