?
Solved

MS SQL in Perl ?

Posted on 2001-06-13
3
Medium Priority
?
228 Views
Last Modified: 2011-09-20
Here is my "select" part :

#!C:\perl\bin\perl

use DBI;
$dbHandle = (DBI->connect('DBI:ADO:DSN', 'sa', ''));
$sql = "SELECT * FROM Test";
$statementHandle = $dbHandle->prepare($sql);
$statementHandle->execute() || die $statementHandle->errstr;

while (($cat1) = $statementHandle->fetchrow_array )
{
     print $cat1."\n";
 }

Above script works fine.  I just wonder how can I insert some value into the table ?
May I have some example script for insert ?
0
Comment
Question by:johnmemor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:johnmemor
ID: 6189394
Here is my "insert" part :

#!C:\perl\bin\perl

 use DBI;
 $dbHandle = (DBI->connect('DBI:ADO:DSN', 'sa', ''));
 $sql = "insert into Test (name) values(\"some_value\")";
 $statementHandle = $dbHandle->prepare($sql);
 $statementHandle->execute() || die $statementHandle->errstr;


I got error after execution.
0
 
LVL 10

Accepted Solution

by:
makerp earned 40 total points
ID: 6190339
$sql = "INSERT INTO table (colname) VALUES (".$some_val.")"

where $some_val is a number, if its a string then wrap it in single quotes like this

$sql = "INSERT INTO table (colname) VALUES ('".$some_val."')"

hope this helps
0
 

Author Comment

by:johnmemor
ID: 6190589
How can I get the row count ?

This is what I have :

$rowCount = $dbh->do($sql);
print $rowCount."\n";


and I got -1, I have more than 1 record in the table.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question