Solved

Update a adoquery based on the sid'ID'.

Posted on 2006-11-05
5
306 Views
Last Modified: 2010-04-05
I have a query i use to get info from the database and display in a listview. Code Below.
var
  colName: string;
  list: TListItem;
begin
  colName:= cmbListName.Text; //Assigns the list name to colName from a combobox
  With QueryManageListView do
  begin
      Close;
      Parameters.ParamByName('pList').Value := colName;
      Open;
      ListView2.Items.Clear;      // Empty the ListView.
      // Loop through the records returned by the query and add the
      // EMail values to the ListView.
     while not EOF do
     begin

       //list := ListView2.Items.Add;
      // with list do

       ListView2.Items.Add;
       ListView2.Items[ListView2.Items.Count-1].Caption := FieldByName('Salutation').AsString;
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('FirstName').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('LastName').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Company').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Address1').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Address2').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('City').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('State').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Zip').AsVariant);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Country').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Phone').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Fax').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.Add(FieldByName('Email').AsString);
       ListView2.Items[ListView2.Items.Count-1].SubItems.add(FieldByName('ID').AsString);
       label6.Caption:=FieldbyName('ID').AsString;
       Next;

     end; { while not EOF do }
     Close;
  end; { With ADOQuery1 do }
I then put this info on a new form4 with the info displayed in edits. Code below.
If assigned(listview2.selected) then
  begin
     form4.edit1.text := listview2.items[listview2.selected.index].caption;
     form4.edit2.text := listview2.items[listview2.selected.index].subitems[0];
     form4.edit3.text := listview2.items[listview2.selected.index].subitems[1];
     form4.edit4.text := listview2.items[listview2.selected.index].subitems[2];
     form4.edit5.text := listview2.items[listview2.selected.index].subitems[3];
     form4.edit6.text := listview2.items[listview2.selected.index].subitems[4];
     form4.edit7.text := listview2.items[listview2.selected.index].subitems[5];
     form4.edit8.text := listview2.items[listview2.selected.index].subitems[6];
     form4.edit9.text := listview2.items[listview2.selected.index].subitems[7];
     form4.edit10.text := listview2.items[listview2.selected.index].subitems[8];
     form4.edit11.text := listview2.items[listview2.selected.index].subitems[9];
     form4.edit12.text := listview2.items[listview2.selected.index].subitems[10];
     form4.edit13.text := listview2.items[listview2.selected.index].subitems[11];
     form4.edit14.text := listview2.items[listview2.selected.index].subitems[12];
     form4.show;

end; .
I am haveing problems changeing the Info of the selected record. I get the Id on the form4 . The id is edit14 . But how can i update this selected record and make sure it is the right ID.
Thanks for looking and or helping.
Grant
0
Comment
Question by:Grant Fullen
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17879438
You dont need to be so complicated on the selection

Form4.Edit1.text := Listview2.Selected.Caption
Form4.Edit2.text := Listview2.Selected.Subitems[x]

etc
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17879445
Also on the creation

list := ListView2.Items.Add;
with list do
begin
  list.Caption := Trim(  FieldByName('Salutation').AsString);
  list.Subitems[x] := Trim( FieldByName('FirstName').AsString);

  etc

end;
0
 

Author Comment

by:Grant Fullen
ID: 17885199
Ok I can change that . How can i update or insert the data on form 4 into the database based on the ID .
Thanks
Grant
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 25 total points
ID: 17886950
Ok what is the entire steps you are trying to do.

1) Populate listview from database
2) On select record in listview, populate Form4 with item data
3) Click button? and update data in database with record from Form4

Is this correct?
When would you be inserting instead of updating.
0
 

Author Comment

by:Grant Fullen
ID: 17925352
I gave up on the query and used an adotable. THanks for looking or posting.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now