Data not saved to the database

Hi

I use this code, but the data is not saved to the database.

I also have a TWebDbGrid on the form. The Id an aName show in the dbgrid after save, but is not saved to the database.

The Xdataserver is working, the dbgrid shows all record from the database.

DefaultEntityPermissions are set to List-Get-Insert=True. Cors is *.

What am I missing?

unit MainUnit;

interface

uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, Data.DB, WEBLib.DB, Vcl.Controls, Vcl.Grids,
WEBLib.DBCtrls, XData.Web.JsonDataset, XData.Web.Dataset, XData.Web.Connection,
Vcl.StdCtrls, WEBLib.StdCtrls;

type
TfrmMain = class(TWebForm)
XDataWebConnection1: TXDataWebConnection;
XDataWebDataSet1: TXDataWebDataSet;
WebDBGrid1: TWebDBGrid;
WebDataSource1: TWebDataSource;
WebLabel1: TWebLabel;
WebButton1: TWebButton;
WebEdit1: TWebEdit;
procedure XDataWebConnection1Connect(Sender: TObject);
procedure WebButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.WebButton1Click(Sender: TObject);
begin

//xdatawebdataset1.open;

//showmessage(inttostr(xdatawebdataset1.RecordCount));

xdatawebdataset1.Insert;

xdatawebdataset1.FieldByName('Id').AsInteger:=3;
xdatawebdataset1.FieldByName('Navn').AsString:=webedit1.Text;

xdatawebdataset1.Post;
xdatawebdataset1.ApplyUpdates;

//xdatawebdataset1.close;

end;

procedure TfrmMain.XDataWebConnection1Connect(Sender: TObject);
begin
xdatawebdataset1.Load;
end;

First thing is to inspect the browser developer tools and check the network tab to have a good idea of the requests being sent to the server. Web Applications with TMS Web Core | TMS XData documentation

Please let us know the content of the requests of the network tab.

Why is database and the Web so extremely difficult to make, I have done database work for years and years, but.... :slight_smile:

From Google Chrome:

<noscript>Your browser does not support JavaScript!</noscript>
<link rel="icon" href="data:;base64,=">

<title>TMS Web Project</title>
<script type="text/javascript" src="ProsjektKlienten.js"></script>
<style>
</style>

Kind regards,
Ole

Can this help?

Snap2

Some more info.

When I post to the database and do a
showmessage(inttostr(xdatawebdataset1.RecordCount));
the count is incremented by 1, but the record is not saved to the database.

Well, you can clearly in console see your web application is raising errors. One of them is exactly the request to the XData server, which is returning a 403 forbidden code. So your XData server is rejecting the query.

You should inspect why is it so. There might be many reasons for that. In the "Response" tab you might have additional information there in JSON format. You should also check if your server is rejecting non-authenticating messages. You should also check if the URL is correct, is your server working correctly at that URL address?