Solved

Update a adoquery based on the sid'ID'.

Posted on 2006-11-05
5
308 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

912 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

20 Experts available now in Live!

Get 1:1 Help Now