Page 1 of 1

Change fieldvalues from a specified record?

Posted: Thu 30 Nov 2006 02:21
by mysqluser
hello

i tried to search in this forum and in mydac help but i dont found any solution for my problem. i want to change some or all fields from a record in any table. what i know is the recNo and which fieldvalues i need to change. but how do i do that (on-the-fly)?

i try it like this:

Code: Select all

    	App->MyQuery->SQL->Text = "select * from Profiles";
        App->MyQuery->Open();
		for(int i = 0; i Items->Count; i++)
    	{
            if(ProfilesList->Items->Item[i]->Checked)
            {
    			App->MyQuery->RecNo = StrToInt(ProfilesList->Items->Item[i]->Caption); //RecNo which i need to change fieldvalues
                App->MyQuery->FieldByName("Age")->AsInteger = 0;
                App->MyQuery->UpdateRecord();
            }
    	}
and how do i get fieldvalues from a specified recordnumber?

Posted: Fri 01 Dec 2006 13:49
by Antaeus
To read/write field values of a specific record, you should scroll to this record in any way (using RecNo like in your example, using the Locate method, using a sequence of Next methods etc). TDataSet class does not allow another kind of access to field values.

Posted: Fri 01 Dec 2006 22:51
by mysqluser
hm i saw now there is a method called Edit(); can i do this with it? seems like. i do it now like

Code: Select all

App->MyQuery->SQL->Text = "SELECT * FROM Profiles WHERE `ID` = '2'";
App->MyQuery->Open();
App->MyQuery->Edit();
App->MyQuery->FieldByName("Name")->AsString = Name->Text;
App->MyQuery->Post();
is that correct?

Posted: Mon 04 Dec 2006 07:51
by Antaeus
Yes, this code looks correct.