BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ADO Command Parameter error on second pass

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Robert Sims
Guest





PostPosted: Wed May 09, 2007 1:35 am    Post subject: ADO Command Parameter error on second pass Reply with quote



I'm at a loss with the code below. Basically, I have a web-table with 2
rows in it. The ADO Command simply tosses each row into a table in the
database...except this one errors out on the second round.

The code below executes perfectly the first time through. On the second
pass, it errors out with Parameter Project_Number not found.

Any help would be greatly appreciated.
-Robert
=====================================================


for loop := 0 to TIWAdvWebGrid1.TotalRows-1 do
begin
if TIWAdvWebGrid1.Cells[1,loop] <> '' then
begin
ADOCom3.Parameters.ParamByName('Project_Number').Value :=
strDate;
ADOCom3.Parameters.ParamByName('Phase').Value :=
TIWAdvWebGrid1.Cells[1,loop];
ADOCom3.Parameters.ParamByName('SubPhase').Value :=
TIWAdvWebGrid1.Cells[2,loop];
ADOCom3.Parameters.ParamByName('Description').Value :=
TIWAdvWebGrid1.Cells[3,loop];
ADOCom3.Parameters.ParamByName('Start').Value :=
TIWAdvWebGrid1.Cells[4,loop];
ADOCom3.Parameters.ParamByName('Stop').Value :=
TIWAdvWebGrid1.Cells[5,loop];
ADOCom3.Parameters.ParamByName('LaborHours').Value :=
TIWAdvWebGrid1.Cells[6,loop];
ADOCom3.Parameters.ParamByName('Labor').Value :=
TIWAdvWebGrid1.Cells[7,loop];
ADOCom3.Parameters.ParamByName('Reimbursable').Value :=
TIWAdvWebGrid1.Cells[8,loop];
ADOCom3.Parameters.ParamByName('Consultant').Value :=
TIWAdvWebGrid1.Cells[9,loop];
ADOCom3.Parameters.ParamByName('Other').Value :=
TIWAdvWebGrid1.Cells[10,loop];
ADOCom3.Parameters.ParamByName('Total').Value :=
TIWAdvWebGrid1.Cells[11,loop];
if (TIWAdvWebGrid1.Cells[2,loop] <> 'D') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'd') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'F') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'f') then
begin
str1 := 'INSERT INTO PS2_Main (Project_Number, Phase,
SubPhase, ' +
'Description, Start, Stop, LaborHours, Labor,
Reimbursable, ' +
'Consultant, Other, Total) ' +
'VALUES (:Project_Number, :Phase, :SubPhase,
:Description, :Start, ' +
':Stop, :LaborHours, :Labor, :Reimbursable,
:Consultant, :Other, :Total) ';
end
else
begin
str1 := 'INSERT INTO PS2_Misc (Project_Number, Phase,
SubPhase, ' +
'Description, Start, Stop, LaborHours, Labor,
Reimbursable, ' +
'Consultant, Other, Total) ' +
'VALUES (:Project_Number, :Phase, :SubPhase,
:Description, :Start, ' +
':Stop, :LaborHours, :Labor, :Reimbursable,
:Consultant, :Other, :Total) ';
end;
ADOCom3.CommandText := str1;
ADOCom3.Prepared := True;
try
ADOCom3.Execute;
finally
ADOCom3.CommandText := '';
str1 := '';
end;
end;
end;
Back to top
Clayton Arends
Guest





PostPosted: Wed May 09, 2007 8:06 am    Post subject: Re: ADO Command Parameter error on second pass Reply with quote



When the 'CommandText' property is altered the 'Parameters' list is emptied.
Try setting the values of your parameters *after* the SQL has been assigned:

for loop := 0 to TIWAdvWebGrid1.TotalRows-1 do
begin
if TIWAdvWebGrid1.Cells[1,loop] <> '' then
begin
if (TIWAdvWebGrid1.Cells[2,loop] <> 'D') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'd') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'F') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'f') then
begin
str1 := '...';
end
else
begin
str1 := '...';
end;
ADOCom3.CommandText := str1;

// Assuming ParamCheck is "True"
ADOCom3.Parameters.ParamByName('Project_Number').Value := strDate;
ADOCom3.Parameters.ParamByName('Phase').Value :=
TIWAdvWebGrid1.Cells[1,loop];
// ... etc ...

try
ADOCom3.Execute;
finally
ADOCom3.CommandText := '';
str1 := '';
end;
end;
end;

If 'ParamCheck' is not set to True then you will need to add your parameters
again before setting their values.

HTH,
- Clayton
Back to top
Brian Bushay TeamB
Guest





PostPosted: Wed May 09, 2007 8:11 am    Post subject: Re: ADO Command Parameter error on second pass Reply with quote



Quote:
I'm at a loss with the code below. Basically, I have a web-table with 2
rows in it. The ADO Command simply tosses each row into a table in the
database...except this one errors out on the second round.

The code below executes perfectly the first time through. On the second
pass, it errors out with Parameter Project_Number not found.

When you set commandText = ''
you remove the parameters.
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com
Back to top
Kevin Frevert
Guest





PostPosted: Wed May 09, 2007 5:27 pm    Post subject: Re: ADO Command Parameter error on second pass Reply with quote

Robert,

Along with Brian's answer, I recommend not 'binding' your UI to updating
the database in that manner. It's not testable outside the UI and prone to
the 'copy/paste' form of code inheritance.

I recommend:
- Placing the insert script in a TADOCommand (at design time, parameters
will/should be automatically set up)
- Creating a method on a datamodule (business object) to insert the data
- ex. function InsertProject(...parameters..) :Boolean;
- Call the method from the UI, passing the values from the grid or wherever

If you want to see an example, I can post one to the
borland.public.attachments

Good luck,
krf

"Robert Sims" <robertsims (AT) nojunkspam (DOT) bellsouth.net> wrote in message
news:4640de4f (AT) newsgroups (DOT) borland.com...
Quote:
I'm at a loss with the code below. Basically, I have a web-table with 2
rows in it. The ADO Command simply tosses each row into a table in the
database...except this one errors out on the second round.

The code below executes perfectly the first time through. On the second
pass, it errors out with Parameter Project_Number not found.
Back to top
Robert Sims
Guest





PostPosted: Wed May 09, 2007 11:51 pm    Post subject: Re: ADO Command Parameter error on second pass Reply with quote

Thanks! That solved it!

"Robert Sims" <robertsims (AT) nojunkspam (DOT) bellsouth.net> wrote in message
news:4640de4f (AT) newsgroups (DOT) borland.com...
Quote:
I'm at a loss with the code below. Basically, I have a web-table with 2
rows in it. The ADO Command simply tosses each row into a table in the
database...except this one errors out on the second round.

The code below executes perfectly the first time through. On the second
pass, it errors out with Parameter Project_Number not found.

Any help would be greatly appreciated.
-Robert
=====================================================


for loop := 0 to TIWAdvWebGrid1.TotalRows-1 do
begin
if TIWAdvWebGrid1.Cells[1,loop] <> '' then
begin
ADOCom3.Parameters.ParamByName('Project_Number').Value :=
strDate;
ADOCom3.Parameters.ParamByName('Phase').Value :=
TIWAdvWebGrid1.Cells[1,loop];
ADOCom3.Parameters.ParamByName('SubPhase').Value :=
TIWAdvWebGrid1.Cells[2,loop];
ADOCom3.Parameters.ParamByName('Description').Value :=
TIWAdvWebGrid1.Cells[3,loop];
ADOCom3.Parameters.ParamByName('Start').Value :=
TIWAdvWebGrid1.Cells[4,loop];
ADOCom3.Parameters.ParamByName('Stop').Value :=
TIWAdvWebGrid1.Cells[5,loop];
ADOCom3.Parameters.ParamByName('LaborHours').Value :=
TIWAdvWebGrid1.Cells[6,loop];
ADOCom3.Parameters.ParamByName('Labor').Value :=
TIWAdvWebGrid1.Cells[7,loop];
ADOCom3.Parameters.ParamByName('Reimbursable').Value :=
TIWAdvWebGrid1.Cells[8,loop];
ADOCom3.Parameters.ParamByName('Consultant').Value :=
TIWAdvWebGrid1.Cells[9,loop];
ADOCom3.Parameters.ParamByName('Other').Value :=
TIWAdvWebGrid1.Cells[10,loop];
ADOCom3.Parameters.ParamByName('Total').Value :=
TIWAdvWebGrid1.Cells[11,loop];
if (TIWAdvWebGrid1.Cells[2,loop] <> 'D') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'd') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'F') or
(TIWAdvWebGrid1.Cells[2,loop] <> 'f') then
begin
str1 := 'INSERT INTO PS2_Main (Project_Number, Phase,
SubPhase, ' +
'Description, Start, Stop, LaborHours, Labor,
Reimbursable, ' +
'Consultant, Other, Total) ' +
'VALUES (:Project_Number, :Phase, :SubPhase,
:Description, :Start, ' +
':Stop, :LaborHours, :Labor, :Reimbursable,
:Consultant, :Other, :Total) ';
end
else
begin
str1 := 'INSERT INTO PS2_Misc (Project_Number, Phase,
SubPhase, ' +
'Description, Start, Stop, LaborHours, Labor,
Reimbursable, ' +
'Consultant, Other, Total) ' +
'VALUES (:Project_Number, :Phase, :SubPhase,
:Description, :Start, ' +
':Stop, :LaborHours, :Labor, :Reimbursable,
:Consultant, :Other, :Total) ';
end;
ADOCom3.CommandText := str1;
ADOCom3.Prepared := True;
try
ADOCom3.Execute;
finally
ADOCom3.CommandText := '';
str1 := '';
end;
end;
end;
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.