Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Update a adoquery based on the sid'ID'.

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

609 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