Recent

Author Topic: Component to sdf file - Microsoft SQL Server database  (Read 1456 times)

TRon

  • Hero Member
  • *****
  • Posts: 833
Re: Component to sdf file - Microsoft SQL Server database
« Reply #15 on: January 31, 2023, 12:13:11 am »
You confuse the truth,
That seem to happen when meddling with things that one has no experience with  :)

Quote
I don't understand. I've never done with the database before.
Tbh that was a bit obvious as you also linked to a youtube video that does absolutely nothing with SDF / SQL server compact.

The video only shows that Lazarus is capable of developing database applications in this particular video by connecting to a firebird database.

You wrote:
I've bought a piece of software that stores its database in an .sdf file
You seem to have purchased software that stores its data in a proprietary database format.

According to the wiki the origin of that database format is EOL and has been so for many years (https://en.wikipedia.org/wiki/SQL_Server_Compact).

Try to see if your software is able to store/save/export the database to another format that /is/ supported by Free Pascal/Lazarus and repeat the quest(ion).

Quote
So is it unsolvable through Lazarus?
See paweld's answer.

Personally I would not bother so would advise against it (but I have not a clue about your restrictions/freedoms).

paweld

  • Hero Member
  • *****
  • Posts: 621
Re: Component to sdf file - Microsoft SQL Server database
« Reply #16 on: January 31, 2023, 09:29:32 am »
You can also connect via OleDB, using the ComObj unit.
An example is attached.
The system must have Microsoft SQL Server Compact 4 installed: https://www.microsoft.com/en-us/download/details.aspx?id=30709
Best regards / Pozdrawiam
paweld

Mi-Ki

  • Jr. Member
  • **
  • Posts: 67
Re: Component to sdf file - Microsoft SQL Server database
« Reply #17 on: January 31, 2023, 10:34:16 am »
paweld - Thank you very much, it works.  :D

Need to work with the table VAZENI
There is Stringgrid.
When I add another line, how to save?

paweld

  • Hero Member
  • *****
  • Posts: 621
Re: Component to sdf file - Microsoft SQL Server database
« Reply #18 on: January 31, 2023, 03:01:46 pm »
I have expanded to include the ability to add records - attached.

Best regards / Pozdrawiam
paweld

Mi-Ki

  • Jr. Member
  • **
  • Posts: 67
Re: Component to sdf file - Microsoft SQL Server database
« Reply #19 on: January 31, 2023, 04:59:15 pm »
I have expanded to include the ability to add records - attached.

Thank you very much. :)
« Last Edit: January 31, 2023, 08:03:44 pm by Mi-Ki »

paweld

  • Hero Member
  • *****
  • Posts: 621
Re: Component to sdf file - Microsoft SQL Server database
« Reply #20 on: January 31, 2023, 08:00:20 pm »
In the previous version, there is a bug related to the formatting of the date when adding a record - the database accepts the format yyyy-mm-dd, so as in the system was different it threw an error. Attached is the new version, and below is just the modified function:
Code: Pascal  [Select][+][-]
  1. function TForm2.ValueToSql(idx: Integer): String;
  2. var
  3.   cn: ShortString;
  4.   i, j: Integer;
  5.   fs: TFormatSettings;
  6. begin
  7.   fs.DecimalSeparator := '.';
  8.   fs.ShortDateFormat := 'yyyy/mm/dd';
  9.   fs.DateSeparator := '-';
  10.   fs.LongTimeFormat := 'hh:nn:ss';
  11.   fs.TimeSeparator := ':';
  12.   Result := '';
  13.   case Form1.tablestruct[idx]._type of
  14.     'int', 'bigint', 'numeric', 'decimal', 'float': cn := 'TFloatSpinEdit';
  15.     'varchar', 'char', 'nvarchar', 'nchar': cn := 'TEdit';
  16.     'text', 'ntext': cn := 'TMemo';
  17.     'date', 'time', 'datetime': cn := 'TDateTimePicker';
  18.   end;
  19.   j := -1;
  20.   for i := 0 to Panel1.ComponentCount - 1 do
  21.   begin
  22.     if Panel1.Components[i].ClassName = cn then
  23.     begin
  24.       if Panel1.Components[i].Tag = idx then
  25.       begin
  26.         j := i;
  27.         break;
  28.       end;
  29.     end;
  30.   end;
  31.   case Form1.tablestruct[idx]._type of
  32.     'int', 'bigint', 'numeric', 'decimal', 'float': Result := FormatFloat('0.######', TFloatSpinEdit(Panel1.Components[j]).Value, fs);
  33.     'varchar', 'char', 'nvarchar', 'nchar': Result := '''' + StringReplace(TEdit(Panel1.Components[j]).Text, '''', '''''', [rfReplaceAll]) + '''';
  34.     'text', 'ntext': Result := '''' + StringReplace(TMemo(Panel1.Components[j]).Lines.Text, '''', '''''', [rfReplaceAll]) + '''';
  35.     'date': Result := '''' + DateToStr(TDateTimePicker(Panel1.Components[j]).Date, fs) + '''';
  36.     'time': Result := '''' + TimeToStr(TDateTimePicker(Panel1.Components[j]).Time, fs) + '''';
  37.     'datetime': Result := '''' + DateTimeToStr(TDateTimePicker(Panel1.Components[j]).DateTime, fs) + '''';
  38.   end;
  39. end;    
  40.  
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018