导航:
论坛 -> 数据库专区
斑竹:liumazi,waterstone
作者:
2023/5/24 20:39:52
标题:
datasnap中用TFDStoredProc提交update命令时的问题
浏览:606
加入我的收藏
楼主:
我用datasnap做了个三层的服务器,有个修改信息的函数如下 function TServerMethods1.ChangeData(Value: string): Integer; var qry: TFDQuery; begin qry := TFDQuery.Create(nil); try qry.Connection := con1; qry.SQL.Text := Value; qry.ExecSQL; Result := qry.RowsAffected; finally qry.Free; end; end; 返回值是qry.RowsAffected,也就是受影响的行数,我在客户端用TFDStoredProc function TForm1.ChangeData(const AText: string): Integer; var MyProc: TFDStoredProc; begin MyProc := TFDStoredProc.Create(nil); MyProc.Connection := con1; try //con1.Connected := true; MyProc.Close; MyProc.Unprepare; MyProc.StoredProcName := 'TServerMethods1.ChangeData'; MyProc.Prepare; MyProc.ParamByName('Value').Value := AText; MyProc.ExecProc; //这里用MyProcExecFun为何出错? Result:=MyProc.RowsAffected; MyProc.Close; finally MyProc.Free; end; end; 以上函数的返回值为MyProc.RowsAffected,但是这个值却一直为零,不知为何,求解。难道必须要在服务端用out的参数来返回受影响的行数吗?
----------------------------------------------
作者:
2023/5/24 23:40:05
1楼:
MyProc.StoredProcName = a PROCEDURE not a function not?
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2023/5/24 23:42:32
2楼:
https://docwiki.embarcadero.com/Libraries/Sydney/en/FireDAC.Comp.Client.TFDStoredProc Use TFDStoredProc to execute server-side stored procedures, browse the result sets, and edit the result set records.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
2023/5/25 0:52:19
3楼:
To emailx45 请看帖子中的TServerMethods1.ChangeData函数
----------------------------------------------
作者:
2023/5/25 9:05:21
4楼:
请大神看看,在线等!
----------------------------------------------
作者:
2023/5/25 15:18:45
5楼:
修改信息不能这样做,datasnap需要结合fdjsondataset才能增删改查。服务器端: 修改: LApply := TFDJSONDeltasApplyUpdates.Create(ADeltaList); // Create the apply object LApply.ApplyUpdates(0, FDQUpdate.Command); 查询: Result := TFDJSONDataSets.Create; //使用反射将查询结果转化为TFDJSONDataSets返回客户端 TFDJSONDataSetsWriter.ListAdd(Result, FDQComm);
----------------------------------------------
-
作者:
2023/5/25 21:26:53
6楼:
楼主,我觉得你的概念可能有问题。 DataSnap 是三层,所有和数据库操作相关的,应该是在服务器端。 你在客户端做数据库操作,你的客户端如何建立数据库连接? 或者我理解错了你的代码?
----------------------------------------------
-
作者:
2023/5/26 13:06:59
7楼:
MyProc.StoredProcName := 'TServerMethods1.ChangeData'; 先不说别的,你这就不是存储过程,这个不是你例子里服务端的服务么? 还是需要先补补数据库知识。
----------------------------------------------
-
作者:
2023/5/28 21:40:20
8楼:
是服务器的函数,客户端调用服务端函数时,如何取得服务器函数ChangeData函数中返回的qry.RowsAffected的值。
----------------------------------------------
作者:
2023/5/28 22:02:16
9楼:
你确信服务端函数是这么调用的么?!
----------------------------------------------
-
作者:
2023/5/29 3:46:39
10楼:
unit ServerMethodsUnit1; ... type {$METHODINFO ON} TServerMethods1 = class(TDataModule) FDConnection1: TFDConnection; FDQuery1: TFDQuery; private { Private declarations } public function HowManyRowAffected: integer; <----- end; {$METHODINFO OFF} implementation ... function TServerMethods1.HowManyRowAffected: integer; begin result := -1; // FDQuery1.Close; // Database = Employee.gdb by Embarcadero! // try FDQuery1.Open('Select * from Country'); // Select, Delete, Update... result := FDQuery1.RowsAffected; finally FDQuery1.Close; end; end; end.
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3