Board index » delphi » Command Executes but No Record Inserted

Command Executes but No Record Inserted


2004-09-18 04:27:05 AM
delphi232
I am new to ADO and SQL Server. I am trying to insert a record into a table in a SQLServer database. Here is what I have in code:
with ADOCommand2 do
begin
Parameters[0].Value := Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1;
Parameters[1].Value := 'ORDERs';
Parameters[2].Value := 'U';
Parameters[3].Value := Query_OrdersOrdernum.newvalue + ',' + IntToStr(Query_ItemsItem.newvalue) + ',' + Query_ItemsProdcode.newvalue + ',' + Query_GetRoutingRouting.AsString + ',' + Query_CustsCompany1.AsString + ',' + FloatToStr(Query_ItemsQuantity.newvalue) + ',' + sRevQty + ',' + sReqdate + ',' + sOrderdate + ',' + sCurDateTime + ',' + sDeliverTo + ',' + sOrderCode;
Execute;
showmessage('after executed ' + IntToStr(Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1));
end;
The showmessage line is executed therefore I am assuming the 'Execute' line before it runs. However there is no record inserted into the table. Am I missing something? Thanks.
 
 

Re:Command Executes but No Record Inserted

"Rhea Grason" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and SQL Server. I am trying to insert a record into a
table in a SQLServer database. Here is what I have in code:

with ADOCommand2 do
begin
Parameters[0].Value :=
Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1;
Parameters[1].Value := 'ORDERs';
Parameters[2].Value := 'U';
Parameters[3].Value := Query_OrdersOrdernum.newvalue + ',' +
IntToStr(Query_ItemsItem.newvalue) + ',' + Query_ItemsProdcode.newvalue +
',' + Query_GetRoutingRouting.AsString + ',' +
Query_CustsCompany1.AsString + ',' +
FloatToStr(Query_ItemsQuantity.newvalue) + ',' + sRevQty + ',' + sReqdate
+ ',' + sOrderdate + ',' + sCurDateTime + ',' + sDeliverTo + ',' +
sOrderCode;
Execute;
showmessage('after executed ' +
IntToStr(Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1));
end;

The showmessage line is executed therefore I am assuming the 'Execute'
line before it runs. However there is no record inserted into the table.
Am I missing something? Thanks.
We need to see your SQL statement before we can make a comment.
Cheers,
Andrew
 

Re:Command Executes but No Record Inserted

You must commit your changes
"Rhea Grason" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and SQL Server. I am trying to insert a record into a
table in a SQLServer database. Here is what I have in code:

with ADOCommand2 do
begin
Parameters[0].Value :=
Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1;
Parameters[1].Value := 'ORDERs';
Parameters[2].Value := 'U';
Parameters[3].Value := Query_OrdersOrdernum.newvalue + ',' +
IntToStr(Query_ItemsItem.newvalue) + ',' + Query_ItemsProdcode.newvalue +
',' + Query_GetRoutingRouting.AsString + ',' +
Query_CustsCompany1.AsString + ',' +
FloatToStr(Query_ItemsQuantity.newvalue) + ',' + sRevQty + ',' + sReqdate +
',' + sOrderdate + ',' + sCurDateTime + ',' + sDeliverTo + ',' + sOrderCode;
Quote
Execute;
showmessage('after executed ' +
IntToStr(Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1));
end;

The showmessage line is executed therefore I am assuming the 'Execute'
line before it runs. However there is no record inserted into the table.
Am I missing something? Thanks.
 

Re:Command Executes but No Record Inserted

Here is the sql statement:
INSERT INTO orders (order_id, order_number, order_batch, part_id, routing_id) VALUES (:order_id, :ordernum, :item, :product, :routing)
Quote
>>Andrew<XXXX@XXXXX.COM>09/17/2004 6:59:59 PM>>>
"Rhea Grason" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and SQL Server. I am trying to insert a record into a
table in a SQLServer database. Here is what I have in code:

with ADOCommand2 do
begin
Parameters[0].Value :=
Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1;
Parameters[1].Value := 'ORDERs';
Parameters[2].Value := 'U';
Parameters[3].Value := Query_OrdersOrdernum.newvalue + ',' +
IntToStr(Query_ItemsItem.newvalue) + ',' + Query_ItemsProdcode.newvalue +
',' + Query_GetRoutingRouting.AsString + ',' +
Query_CustsCompany1.AsString + ',' +
FloatToStr(Query_ItemsQuantity.newvalue) + ',' + sRevQty + ',' + sReqdate
+ ',' + sOrderdate + ',' + sCurDateTime + ',' + sDeliverTo + ',' +
sOrderCode;
Execute;
showmessage('after executed ' +
IntToStr(Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1));
end;

The showmessage line is executed therefore I am assuming the 'Execute'
line before it runs. However there is no record inserted into the table.
Am I missing something? Thanks.
We need to see your SQL statement before we can make a comment.
Cheers,
Andrew
 

Re:Command Executes but No Record Inserted

How and when do I do that? I have another ADOCommand that inserts a record into a table and it works without a commit.
Quote
>>Mike Shkolnik<XXXX@XXXXX.COM>09/18/2004 12:25:09 AM>>>
You must commit your changes
"Rhea Grason" <XXXX@XXXXX.COM>writes
Quote
I am new to ADO and SQL Server. I am trying to insert a record into a
table in a SQLServer database. Here is what I have in code:

with ADOCommand2 do
begin
Parameters[0].Value :=
Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1;
Parameters[1].Value := 'ORDERs';
Parameters[2].Value := 'U';
Parameters[3].Value := Query_OrdersOrdernum.newvalue + ',' +
IntToStr(Query_ItemsItem.newvalue) + ',' + Query_ItemsProdcode.newvalue +
',' + Query_GetRoutingRouting.AsString + ',' +
Query_CustsCompany1.AsString + ',' +
FloatToStr(Query_ItemsQuantity.newvalue) + ',' + sRevQty + ',' + sReqdate +
',' + sOrderdate + ',' + sCurDateTime + ',' + sDeliverTo + ',' + sOrderCode;
Quote
Execute;
showmessage('after executed ' +
IntToStr(Query_GetLastImportIDT5MAXimport_dataimpdata_id.value + 1));
end;

The showmessage line is executed therefore I am assuming the 'Execute'
line before it runs. However there is no record inserted into the table.
Am I missing something? Thanks.
 

Re:Command Executes but No Record Inserted

See the BeginTrans, CommitTrans and RollbackTrans methods of
TADOConnection. If you are going to use an SQL database server you will
avoid a lot of trouble if you learn about transactions and always
explicitly start and commit your transactions in code.
--
Bill (TeamB)
TeamB cannot answer questions received via email