Solved

Update a adoquery based on the sid'ID'.

Posted on 2006-11-05
5
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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