?
Solved

Update a adoquery based on the sid'ID'.

Posted on 2006-11-05
5
Medium Priority
?
323 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 50 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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