hi,
I have designed a module, which contains a template for insert command.
The code is as under: -
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
-
localtime(time);
-
$year+=1900;
-
$mon++;
-
-
my $col_name = "100";
-
my $ins_name = "pavan";
-
my $ins_id = 3;
-
my $ins_desc = "hi";
-
my $createdby = 1;
-
my $modifiedby = 1;
-
my $table_name = Institution;
-
my (@colnames,@values,@exec_arr);
-
my $now='now';
-
push(@colnames,Institution_Id,Institution_Name,Institution_Desc,Createdby,Createddtm,Modifiedby,Modifieddtm,Customer_Id);
-
my $count = @colnames;
-
push(@values,$ins_id,$ins_name,$ins_desc,$createdby,$now,$modifiedby,$now,100);
-
#print "@colnames";
-
#my @arr2 = sub1($table_name,@colnames,@values);
-
sub1($table_name,@colnames,@values);
-
-
sub sub1
-
{
-
-
push(my @arr,@_);
-
print "@arr";
-
my $tab_name = $arr[0];
-
shift(@arr);
-
print "--------------------------------------- \n";
-
print "$arr[0]";
-
print "--------------------------------------- \n";
-
print "\n<<@arr>>";
-
print " \n$tab_name \n";
-
my $count = scalar(@arr);
-
-
-
print "<<$count>>> \n";
-
my $limit = $count/2;
-
-
-
$i=0;
-
my $var='';
-
print "<$limit> \n";
-
while($i<$limit)
-
{
-
if( ($i) == $limit-1 )
-
{
-
$var = $var . $arr[$i];
-
}
-
else
-
{
-
$var = $var . $arr[$i] . ",";
-
}
-
$i++;
-
}
-
print "\n var:::::::$var";
-
-
$i=$limit++;
-
my $vals='';
-
-
while($i<$count)
-
{
-
if( ($i) == $count-1 )
-
{
-
$vals = $vals . $arr[$i];
-
}
-
else
-
{
-
$vals = $vals . $arr[$i] . ",";
-
}
-
$i++;
-
}
-
print "\n vals:::::::$vals \n";
-
my $sth = $dbh->prepare("insert into $tab_name ($var) values ($vals)");
-
my $resp = $sth->execute();
-
if($resp ne '0E0')
-
{
-
print "Successfully inserted";
-
}
-
-
}
-
I am able to get column names by $var scalar , and all the values in $vals,
but i am getting error while executing the query as under:
DBD::mysql::st execute failed: Unknown column 'pavan' in 'field list' at D:/pavan/Workspace/sample/insert_template.pl line 107.
Use of uninitialized value in string ne at D:/pavan/Workspace/sample/insert_template.pl line 108.
how to correct the mistake?
Thanks & Regards,
Pavan
3 1420
I don't know what the problem is, but looking at your code, you are using the push() function for no reason. You assign initial values to an array using the assignment operator "=", not push().
correct: - @array = ($var, $var2, $var3, etc, etc, etc);
-
incorrect: - push @array,$var, $var2, $var3, etc, etc, etc;
your strings should also all be quoted, for example: - push(@colnames,Institution_Id,Institution_Name,Ins titution_Desc,Createdby,Createddtm,Modifiedby,Modifieddtm,Customer_Id);
should be: - @colnames = qw(Institution_Id Institution_Name Institution_Desc Createdby Createddtm Modifiedby Modifieddtm Customer_Id);
Also, please note that your closing code tag should have a "/' character, not a "%" character.
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics
by: deancoo |
last post by:
I have gotten into the habit of often using copy along with an insert
iterator. There are scenarios where I process quite a lot of data this way.
Can someone give me a general feel as to how much...
|
by: Paul D. Fox |
last post by:
I'd like to populate four dropdowns using code behind. Each dropdown contains the same list. How can I populate them using a subroutine. Something like:
InitializeDropDownList(ddlQuadrant1)...
|
by: Lorenzino |
last post by:
Hi, I have a problem with bindings in a formview.
I have a formview; in the insert template i've created a wizard control and
inside
it i have an HTML table with some textboxes bound to the...
|
by: michga |
last post by:
Hello,
Using docbook 4.4, docbook-xsl 1.70.1 and fop, I've successfully used
this snippet of code in a customized-layer stylesheet to insert one
linebreak:
<xsl:template...
|
by: Brad Baker |
last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL
database. At the top of the page I have the following code:
<%@ Page Language="C#" Debug="true" %>
<%@ import...
|
by: AG |
last post by:
ASP.NET 2.0 aspx page with a FormView bound to an ObjectDataSource to view,
add and edit records.
Can anyone point me to a sample of how to retain the user entered control
values when an insert...
|
by: Jim Langston |
last post by:
I'm working on a program, and at one time I find it necessary to load
classes into a map. Now, these classes don't have default constructors, so
I can't retrieve them using
MyMap.
So I wound...
|
by: =?Utf-8?B?bXBhaW5l?= |
last post by:
Hello,
I am completely lost as to why I can't update a DropDownList inside a
DetailsView after I perform an insert into an object datasource. I tried to
simply it down to the core demostration:...
|
by: Olumide |
last post by:
Hello,
I've got this nice inner class that I'm holds a set of "FrontPoint"
objects as shown below. Unfortunately, the find and insert methods
trigger massive C2784 errors. Would someone please...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |