Unidac Access Edit Record
Posted: Thu 22 Apr 2010 14:34
I am converting from using the TAdoquery component using a Microsoft Access database to the Tuniquery component.
I am trying to edit a record and it it not working. On the form I have a TAccessUniProvider Component as well. In the below example, unless I specify the SETFIELDSREADONLY=FALSE option - I get a message "Unable to modify a read-only dataset". I have tried the other lines that I commented out with no luck. Now with the code below - it appears that it works, but it doesn't really update the record. The before and after results are the same.
procedure TForm1.Button1Click(Sender: TObject);
var
UniConnection : TUniconnection;
query : TUniquery;
begin
UniConnection := TUniconnection.Create(self);
query := TUniquery.Create(self);
try
UniConnection.ProviderName := 'Access';
UniConnection.Database := 'hedis2010.mdb';
UniConnection.Username := 'Admin';
UniConnection.Password := 'xxxxx';
UniConnection.Connected := True;
if Uniconnection.connected then
begin
query.Connection := UniConnection;
//query.Options.QuoteNames := true;
query.Options.SetFieldsReadOnly := false;
//query.LockMode := lmOptimistic;
//query.LocalUpdate := true;
query.SQL.Text := 'select * from [parameters] where Ucase(description) = UCase(:description)';
query.Params[0].Value := 'INDEXSPACE';
query.Active := true;
try
if not query.eof then
begin
showmessage('Before: ' + query.fieldbyname('data').AsString);
query.Edit;
query.fieldbyname('data').AsString := 'test';
query.Post;
query.Refresh;
showmessage('After: ' + query.fieldbyname('data').AsString);
end;
except on e:exception do
showmessage(e.Message);
end;
end;
finally
query.Free;
UniConnection.Free;
end;
end;
I am trying to edit a record and it it not working. On the form I have a TAccessUniProvider Component as well. In the below example, unless I specify the SETFIELDSREADONLY=FALSE option - I get a message "Unable to modify a read-only dataset". I have tried the other lines that I commented out with no luck. Now with the code below - it appears that it works, but it doesn't really update the record. The before and after results are the same.
procedure TForm1.Button1Click(Sender: TObject);
var
UniConnection : TUniconnection;
query : TUniquery;
begin
UniConnection := TUniconnection.Create(self);
query := TUniquery.Create(self);
try
UniConnection.ProviderName := 'Access';
UniConnection.Database := 'hedis2010.mdb';
UniConnection.Username := 'Admin';
UniConnection.Password := 'xxxxx';
UniConnection.Connected := True;
if Uniconnection.connected then
begin
query.Connection := UniConnection;
//query.Options.QuoteNames := true;
query.Options.SetFieldsReadOnly := false;
//query.LockMode := lmOptimistic;
//query.LocalUpdate := true;
query.SQL.Text := 'select * from [parameters] where Ucase(description) = UCase(:description)';
query.Params[0].Value := 'INDEXSPACE';
query.Active := true;
try
if not query.eof then
begin
showmessage('Before: ' + query.fieldbyname('data').AsString);
query.Edit;
query.fieldbyname('data').AsString := 'test';
query.Post;
query.Refresh;
showmessage('After: ' + query.fieldbyname('data').AsString);
end;
except on e:exception do
showmessage(e.Message);
end;
end;
finally
query.Free;
UniConnection.Free;
end;
end;