Page 1 of 1

SQL Server Compact 4.0 and default values

Posted: Sat 04 Jun 2011 17:31
by stojo303
Hi,

I have identified a problem (?) or at least handling that differs between for example SQL Server Express and SQL Server Compact.

Example:

Code: Select all

UC2.SQL.Text := 'SELECT f1, f2, f3 FROM tblX';
with UC2 do
begin
  Open;
  Insert;
  FieldByName('f1').Value := UC1.FieldByName('f1').Value;
  FieldByName('f2').Value := UC1.FieldByName('f2').Value;
  FieldByName('f3').Value := UC1.FieldByName('f3').Value;
  Post;
end;
(UC1 and UC2 are of type TUniQuery, UC1 has been opened before, f1 = string, f2 = string, f3 = int, nullable)

The following works fine with SQL Server Express, but with SQL Compact the assignment of f3 will fail if the value from UC1 is NULL.

Can I get around this somehow with some parameter or such or do I need to rewrite my code?

Thanks in advance, if neccessary, I can provide full example code.

Posted: Sun 05 Jun 2011 09:54
by stojo303
Minimal example code and database sent to your support.

Posted: Mon 06 Jun 2011 11:14
by AndreyZ
Hello,

To solve the problem, you should set the RequiredFields option to False in the following way:

Code: Select all

UC2.Options.RequiredFields := False;

Posted: Mon 06 Jun 2011 12:58
by stojo303
Thanks! That seems to work very well (somemore testing is needed though!)

Great support as always!

Posted: Mon 06 Jun 2011 13:08
by AndreyZ
If any other questions come up, please contact us.