 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Robert Sims Guest
|
Posted: Wed May 09, 2007 1:35 am Post subject: ADO Command Parameter error on second pass |
|
|
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
|
Posted: Wed May 09, 2007 8:06 am Post subject: Re: ADO Command Parameter error on second pass |
|
|
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
|
Posted: Wed May 09, 2007 8:11 am Post subject: Re: ADO Command Parameter error on second pass |
|
|
| 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
|
Posted: Wed May 09, 2007 5:27 pm Post subject: Re: ADO Command Parameter error on second pass |
|
|
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
|
Posted: Wed May 09, 2007 11:51 pm Post subject: Re: ADO Command Parameter error on second pass |
|
|
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 |
|
 |
|
|
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
|
|