Assign + AddField = Problem

Assign + AddField = Problem

Postby _Dejan_ » Mon 28 Dec 2009 07:48

Hi,
I have little problem. I using latest SDAC 4.80.0.54 and have little problem with VirtualTable component.
for example I would like fill data from TMSQuery to TVirtualtable but I get error.
Code: Select all
VirtualTable1.Assign(q_temp);
VirtualTable1.AddField('checked', ftBoolean, 0);


Im also try:
Code: Select all
VirtualTable1.Assign(q_temp);
VirtualTable1.Close;
VirtualTable1.AddField('checked', ftBoolean, 0);
VirtualTable1.Open;


and get same error.
Error:
Debug Output: [28.12.2009 8:36:02] Exception: Field 'ID' cannot be modified\0Dh Process Test.exe (2876)


Table structure in SQL Server:
Code: Select all
TABLE_CATALOG     COLUMN_NAME    COLUMN_DEFAULT DATA_TYPE CHARACTER_MAXIMUM_LENGTH
----------------- -------------- -------------- --------- ------------------------
gps_new           ID             1              No       
gps_new           DESCRIPTION    2              YES       50
gps_new           GPS_ID         3              YES       20


What I would like to do? Have some "virtual table/query" which have data from sql server but with aditional column with name "checked" type = ftboolean.
Thanks for any help.
_Dejan_
 
Posts: 23
Joined: Mon 28 Dec 2009 07:30
Location: Slovenia

Postby Plash » Wed 30 Dec 2009 08:06

We could not reproduce the problem. Please send to support*devart*com a complete small sample that demonstrates the problem, including the script for creating database objects.
Plash
Devart Team
 
Posts: 2844
Joined: Wed 10 May 2006 07:09

Postby _Dejan_ » Thu 31 Dec 2009 07:21

Yesterday Im send example to email. Did you receive it?
_Dejan_
 
Posts: 23
Joined: Mon 28 Dec 2009 07:30
Location: Slovenia

Postby Plash » Thu 31 Dec 2009 12:27

Set the ReadOnly property of TMSQuery to False. The identity field is read-only anyway.

You need to remove a read-only attribute from the field before adding a new field:
Code: Select all
  VirtualTable1.Assign(q_zacasni);
  VirtualTable1.Close;
  VirtualTable1.FieldDefs[0].Attributes :=
    VirtualTable1.FieldDefs[0].Attributes - [faReadOnly];
  VirtualTable1.AddField('checked', ftBoolean, 0);
Plash
Devart Team
 
Posts: 2844
Joined: Wed 10 May 2006 07:09

Postby _Dejan_ » Thu 31 Dec 2009 19:43

Hi thanks for this info. Now it works.
Im do:
Code: Select all
q_zacasni.ReadOnly:=False;
VirtualTable1.Assign(q_zacasni);
VirtualTable1.AddField('checked', ftBoolean, 0);


And it works. Thanks.
_Dejan_
 
Posts: 23
Joined: Mon 28 Dec 2009 07:30
Location: Slovenia

Postby _Dejan_ » Fri 21 Oct 2011 11:14

I would like wake up this thread.
When Im try run another query Im start receiving errors:
Code: Select all
First chance exception at $7C812AFB. Exception class EDatabaseError with message 'Field 'field1' cannot be modified'. Process App.exe (200)


Code:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var q_temp :TMSQuery;
begin
try
  q_temp:=TMSQuery.Create(Self);
  q_temp.Connection:=DataModule1.Connection;
  q_temp.ReadOnly:=False;
  q_temp.SQL.Clear;
  q_temp.SQL.Add('SELECT DISTINCT t.field1, (SELECT table1.field2 + ' + QuotedStr(', ') + ' AS [text()] FROM table1 WHERE table1.field1 = t.field1 ORDER BY table1.field2 FOR XML Path(' + QuotedStr('') + ')) AS field3 FROM table1 t');
  q_temp.Open;

  VirtualTable1.Assign(q_temp);
  VirtualTable1.Close;
  VirtualTable1.FieldDefs[0].Attributes:=VirtualTable1.FieldDefs[0].Attributes - [faReadOnly];
  VirtualTable1.AddField('checked', ftBoolean, 0);
  VirtualTable1.Open;
finally
  q_temp.Close;
  q_temp.Free;
end;
end;



any hint?
_Dejan_
 
Posts: 23
Joined: Mon 28 Dec 2009 07:30
Location: Slovenia

Postby AndreyZ » Tue 25 Oct 2011 14:17

I cannot reproduce the problem. Your code works without any errors. Please specify the exact moment when the 'Field 'field1' cannot be modified' occurs.
AndreyZ
 


Return to VirtualDAC