 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mick Guest
|
Posted: Thu Oct 12, 2006 2:17 pm Post subject: Insert SQL statement using Create Parameter Statement |
|
|
Hi I am trying to insert records into an ado dataset using parameters that
are created at run time i have tried various methods but with each method I
hit a different brick wall can anyone help.
I using ado because the connection will either be connecting to oracle or
mssql depending on customer preference of database and i do not want to
write 2 seperate sets of routines.
My sql statement is
insert into uploadlog (added,machineid,logfile) values
(:added,'test',:logfile);
I have tried 2 ways of trying to get the parameters in each gives a
different error message.
------------------------------------
dstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'''+UserName+''',:logfile)');
DstQry.Parameters.CreateParameter('added',ftDateTime,pdInputOutput,-1,NOW);
DstQry.Parameters.CreateParameter('logfile',ftBlob,pdInputOutput,-1,LogTxt);
try
DstQry.ExecSQL;
except on e:exception do
begin
ShowMEssage('Error Uploading Log File! '+e.Message);
exit;
end;
end;
This gives the error message - OLEDBException multiple step OLEDB operation
generated errors. Check each OLEDB status value. No work was done.
----------------------------------------
The other method i tried is
dstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'''+UserName+''',:logfile)');
DstQry.Parameters.AddParameter;
DstQry.Parameters.AddParameter;
DstQry.Parameters[0].Name := 'added';
DstQry.Parameters[1].Name := 'logfile';
DstQry.Parameters.ParamByName('added').DataType := ftDateTime;
DstQry.Parameters.ParamByName('added').Direction := pdInputOutput;
DstQry.Parameters.ParamByName('added').Value := NOW;
DstQry.Parameters.ParamByName('logfile').DataType := ftblob;
DstQry.Parameters.ParamByName('logfile').Direction := pdInputOutput;
DstQry.Parameters.ParamByName('logFile').Value := LogTxt;
}
try
DstQry.ExecSQL;
except on e:exception do
begin
ShowMEssage('Error Uploading Log File! '+e.Message);
exit;
end;
end;
This gives the eroor message of - Parameter Object is improperly defined,
Inconsistant or incomplete information is provided.
------------------------------------------
I have tried rmoving the blob paraemeter and just working with the
ftdatetime but the results are still the same.
Any Help graetly appreciated!
Mick!
Forever Onwards is the Call. |
|
| Back to top |
|
 |
Brian Bushay TeamB Guest
|
Posted: Fri Oct 13, 2006 7:52 am Post subject: Re: Insert SQL statement using Create Parameter Statement |
|
|
| Quote: | Hi I am trying to insert records into an ado dataset using parameters that
are created at run time i have tried various methods but with each method I
hit a different brick wall can anyone help.
I using ado because the connection will either be connecting to oracle or
mssql depending on customer preference of database and i do not want to
write 2 seperate sets of routines.
My sql statement is
insert into uploadlog (added,machineid,logfile) values
(:added,'test',:logfile);
I have tried 2 ways of trying to get the parameters in each gives a
different error message.
------------------------------------
dstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'''+UserName+''',:logfile)');
DstQry.Parameters.CreateParameter('added',ftDateTime,pdInputOutput,-1,NOW);
DstQry.Parameters.CreateParameter('logfile',ftBlob,pdInputOutput,-1,LogTxt);
try
DstQry.ExecSQL;
except on e:exception do
begin
ShowMEssage('Error Uploading Log File! '+e.Message);
exit;
end;
end;
This gives the error message - OLEDBException multiple step OLEDB operation
generated errors. Check each OLEDB status value. No work was done.
----------------------------------------
The other method i tried is
dstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'''+UserName+''',:logfile)');
DstQry.Parameters.AddParameter;
DstQry.Parameters.AddParameter;
DstQry.Parameters[0].Name := 'added';
DstQry.Parameters[1].Name := 'logfile';
DstQry.Parameters.ParamByName('added').DataType := ftDateTime;
DstQry.Parameters.ParamByName('added').Direction := pdInputOutput;
DstQry.Parameters.ParamByName('added').Value := NOW;
DstQry.Parameters.ParamByName('logfile').DataType := ftblob;
DstQry.Parameters.ParamByName('logfile').Direction := pdInputOutput;
DstQry.Parameters.ParamByName('logFile').Value := LogTxt;
}
try
DstQry.ExecSQL;
except on e:exception do
begin
ShowMEssage('Error Uploading Log File! '+e.Message);
exit;
end;
end;
This gives the eroor message of - Parameter Object is improperly defined,
Inconsistant or incomplete information is provided.
------------------------------------------
I have tried rmoving the blob paraemeter and just working with the
ftdatetime but the results are still the same.
Any Help graetly appreciated!
You never clear your SQL or your Parameters. |
You may be adding to existing SQL or parameters
| Quote: | OLEDBException multiple step OLEDB operation
generated errors |
This error often means you have persistent tfields defined that do not match the
field type returned by the query.
I suggest you first create your parameters at design time and get that code
working first before you try creating parameters in code.
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com |
|
| Back to top |
|
 |
Mick Guest
|
Posted: Fri Oct 13, 2006 1:19 pm Post subject: Re: Insert SQL statement using Create Parameter Statement |
|
|
Thanks Brian.
Done This already. And yes it works fine. But this method is not practicle
for what i am trying to achieve.
If i explain a bit more of what i am trying to achieve that may help.
I am copying records over a wan from database to database using insert sql
statements. I need to keep bandwidth usage to a minimum so no tables. I get
a list of the tables in the database and then get a list of the fields in
the database and attempt to map them through to an identical database stored
locally.
In adavnce i do not know what fields there will be so i cannot create the
paraemeters at design time!
I have tried to copy the field types exact when creating the parameters but
i still get the same eror messages.
i.e.
SrcQry holds a single record from a table and dstqry is the insert query
for loop = number of fields -
DstQry.Parameters.CreateParameter('p'+IntToStr(loop),SrcQry.Field[loop].DataType,pdInputOutput,SrcQry.FieldByName(SrcQry.Fields[loop].FieldName).Size,SrcQry.FieldByName(SrcQry.Fields[loop].FieldName).Value);
Because i get the exact field type from the srcqry i thought this would have
worked no problem but no it doesn't Am i missing a link here in my thinking?
"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote in message
news:ngrti25adkhh75jbl7s938map5tck6obn3 (AT) 4ax (DOT) com...
| Quote: |
Hi I am trying to insert records into an ado dataset using parameters that
are created at run time i have tried various methods but with each method
I
hit a different brick wall can anyone help.
I using ado because the connection will either be connecting to oracle or
mssql depending on customer preference of database and i do not want to
write 2 seperate sets of routines.
My sql statement is
insert into uploadlog (added,machineid,logfile) values
(:added,'test',:logfile);
I have tried 2 ways of trying to get the parameters in each gives a
different error message.
------------------------------------
dstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'''+UserName+''',:logfile)');
DstQry.Parameters.CreateParameter('added',ftDateTime,pdInputOutput,-1,NOW);
DstQry.Parameters.CreateParameter('logfile',ftBlob,pdInputOutput,-1,LogTxt);
try
DstQry.ExecSQL;
except on e:exception do
begin
ShowMEssage('Error Uploading Log File! '+e.Message);
exit;
end;
end;
This gives the error message - OLEDBException multiple step OLEDB
operation
generated errors. Check each OLEDB status value. No work was done.
----------------------------------------
The other method i tried is
dstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'''+UserName+''',:logfile)');
DstQry.Parameters.AddParameter;
DstQry.Parameters.AddParameter;
DstQry.Parameters[0].Name := 'added';
DstQry.Parameters[1].Name := 'logfile';
DstQry.Parameters.ParamByName('added').DataType := ftDateTime;
DstQry.Parameters.ParamByName('added').Direction := pdInputOutput;
DstQry.Parameters.ParamByName('added').Value := NOW;
DstQry.Parameters.ParamByName('logfile').DataType := ftblob;
DstQry.Parameters.ParamByName('logfile').Direction := pdInputOutput;
DstQry.Parameters.ParamByName('logFile').Value := LogTxt;
}
try
DstQry.ExecSQL;
except on e:exception do
begin
ShowMEssage('Error Uploading Log File! '+e.Message);
exit;
end;
end;
This gives the eroor message of - Parameter Object is improperly defined,
Inconsistant or incomplete information is provided.
------------------------------------------
I have tried rmoving the blob paraemeter and just working with the
ftdatetime but the results are still the same.
Any Help graetly appreciated!
You never clear your SQL or your Parameters.
You may be adding to existing SQL or parameters
OLEDBException multiple step OLEDB operation
generated errors
This error often means you have persistent tfields defined that do not
match the
field type returned by the query.
I suggest you first create your parameters at design time and get that
code
working first before you try creating parameters in code.
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com |
|
|
| Back to top |
|
 |
Vitali Kalinin Guest
|
Posted: Fri Oct 13, 2006 2:10 pm Post subject: Re: Insert SQL statement using Create Parameter Statement |
|
|
Why do you trying to create parameters manually in code? In most cases
Delphi wrapper for ADO will handle that for you automatically. So all that
you need is just:
DstQry.SQL.BeginUpdate;
DstQry.SQL.Clear;
DstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'+QuotedStr(UserName)+',:logfile)');
DstQry.SQL.EndUpdate;
DstQry.Parameters.ParamByName('added').Value := NOW;
DstQry.Parameters.ParamByName('logFile').Value := LogTxt;
DstQry.ExecSQL;
BTW TADOCommand is preffered for executing inserts, updates and deletes.
Regards,
Vitali |
|
| Back to top |
|
 |
Mick Guest
|
Posted: Fri Oct 13, 2006 4:29 pm Post subject: Re: Insert SQL statement using Create Parameter Statement |
|
|
Thanks for that Vitali.
My mistake was assuming that if you didn't create the paraemeters at design
time then manuall code would have to be written for run time but it looks as
though the component sorts it out itself.
Nice!
My preliminary test on blob fields are not lloking too good yet but more
testing required.
MICK!
"Vitali Kalinin" <vitkalinin (AT) yahoo (DOT) com> wrote in message
news:452f5814$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Why do you trying to create parameters manually in code? In most cases
Delphi wrapper for ADO will handle that for you automatically. So all that
you need is just:
DstQry.SQL.BeginUpdate;
DstQry.SQL.Clear;
DstQry.SQL.Add('insert into uploadlog (added,machineid,logfile) values
(:added,'+QuotedStr(UserName)+',:logfile)');
DstQry.SQL.EndUpdate;
DstQry.Parameters.ParamByName('added').Value := NOW;
DstQry.Parameters.ParamByName('logFile').Value := LogTxt;
DstQry.ExecSQL;
BTW TADOCommand is preffered for executing inserts, updates and deletes.
Regards,
Vitali
|
|
|
| Back to top |
|
 |
Brian Bushay TeamB Guest
|
Posted: Sat Oct 14, 2006 6:13 am Post subject: Re: Insert SQL statement using Create Parameter Statement |
|
|
| Quote: | Thanks Brian.
Done This already. And yes it works fine. But this method is not practicle
for what i am trying to achieve.
If i explain a bit more of what i am trying to achieve that may help.
I am copying records over a wan from database to database using insert sql
statements. I need to keep bandwidth usage to a minimum so no tables. I get
a list of the tables in the database and then get a list of the fields in
the database and attempt to map them through to an identical database stored
locally.
In adavnce i do not know what fields there will be so i cannot create the
paraemeters at design time!
I have tried to copy the field types exact when creating the parameters but
i still get the same eror messages.
i.e.
SrcQry holds a single record from a table and dstqry is the insert query
for loop = number of fields -
DstQry.Parameters.CreateParameter('p'+IntToStr(loop),SrcQry.Field[loop].DataType,pdInputOutput,SrcQry.FieldByName(SrcQry.Fields[loop].FieldName).Size,SrcQry.FieldByName(SrcQry.Fields[loop].FieldName).Value);
Because i get the exact field type from the srcqry i thought this would have
worked no problem but no it doesn't Am i missing a link here in my thinking?
Use SQL.Clear before adding new SQL |
and
Use Parameters.Clear;
Before trying to create new parameters
--
Brian Bushay (TeamB)
Bbushay (AT) NMPLS (DOT) com |
|
| 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
|
|