http://wolfsoft.nugoo.com/
这里的源码中心有个婚纱摄影的例子,你看看有帮助
database1.starttransaction;
try
for i:=0 to listview.items.count-1 do
begin
for j:=0 to listview1.items.subitem.count-1 do
insertsql;
什么意思,QUERY执行一次提交所有对应记录你就用循环来给listview赋值就是了
procedure AddFeeItemDetail(FeeItemInfo : TFeeItemInfo);
var
FeeItem : TListItem;
begin
if Assigned(Node.Data) then
begin
FeeItem := TListItem.Create(lvItemResult.Items);
FeeItem.SubItems.Add(FeeItemInfo.FeeItemID);
FeeItem.SubItems.Add(FeeItemInfo.FeeItemName);
FeeItem.Data := FeeItemInfo;
lvItemResult.Items.AddItem(FeeItem);
end;
end;
procedure ShowListView_Channel(ClientDataSet: TClientDataSet; ListView: TSortListView; ImageIndex: Integer);
var
i, j: Integer;
ListItem: TSortListItem;
begin
ListView.Items.BeginUpdate;
ListView.Items.Clear;
with ClientDataSet do
begin
for i := 0 to RecordCount - 1 do
begin
with ListView.Items do
begin
ListItem := Add;
for j := 0 to Fields.Count - 1 do
With Item do
begin
if j = 0 then
if Fields[j].FieldName = 'PRICE' then
ListItem.SubItems.Add(FormatFloat('0.00',Fields[j].AsFloat))
else
ListItem.Caption := Fields[j].AsString
else
if Fields[j].FieldName = 'PRICE' then
ListItem.SubItems.Add(FormatFloat('0.00',Fields[j].AsFloat))
else
ListItem.SubItems.Add(Fields[j].AsString);
end;
ListItem.ImageIndex := ImageIndex;
Next;
end;
end;
end;
ListView.Items.EndUpdate;
end;
我的代码如下:(这个是提交单个记录用的)
var
i,j:integer;
Ptr:Tlistitem;
insertsql:string;
begin
for i:=0 to listview1.Items.Count-1 do
begin
Ptr:=listview1.Items;
insertsql:=format('INSERT INTO `测试` (`字段1`,`字段2`) VALUES(''%s'',''%s'') ',[Ptr.Caption,Ptr.SubItems.Strings[0]]);
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add(insertsql);
Query1.Prepare;
Query1.ExecSQL;
end;
end;
我应该如何修改呢!