Change fieldvalues from a specified record?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mysqluser
Posts: 27
Joined: Fri 17 Nov 2006 11:48

Change fieldvalues from a specified record?

Post by mysqluser » Thu 30 Nov 2006 02:21

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?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Fri 01 Dec 2006 13:49

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.

mysqluser
Posts: 27
Joined: Fri 17 Nov 2006 11:48

Post by mysqluser » Fri 01 Dec 2006 22:51

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?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Mon 04 Dec 2006 07:51

Yes, this code looks correct.

Post Reply