I have a TSqlDataSet which has a blob field, I need to get the data of this blob field in the BeforeUpdateRecord event of the provider and execute an update command, I've tried this:
我有一个带有blob字段的TSqlDataSet,我需要在提供程序的BeforeUpdateRecord事件中获取此blob字段的数据并执行更新命令,我试过这个:
Cmd := TSQLQuery.Create(nil);
try
Cmd.SQLConnection := SQLConnection;
Cmd.CommandText := 'UPDATE MYTABLE SET IMAGE = :PIMAGE WHERE ID = :PID';
Cmd.Params.CreateParam(ftBlob, 'PIMAGE ', ptInput).Value := DeltaDS.FieldByName('IMAGE').NewValue; //blob field
Cmd.Params.CreateParam(ftString, 'PID', ptInput).Value := DeltaDS.FieldByName('ID').NewValue;
Cmd.ExecSQL;
finally
Cmd.Free;
end;
When I execute that I get an EDatabaseError with message: 'No value for parameter PIMAGE.
当我执行时,我得到一个带有消息的EDatabaseError:'没有参数PIMAGE的值。
What am I missing?
我错过了什么?
2 个解决方案
#1
2
Answering my own question, the correct way to do it is the following:
回答我自己的问题,正确的方法如下:
const
SQL = 'UPDATE MYTABLE SET IMAGE = :PIMAGE WHERE ID = :PID;';
var
Params: TParams;
begin
Params := TParams.Create(nil);
try
Params.CreateParam(ftBlob, 'PIMAGE', ptInput).AsBlob := DeltaDS.FieldByName('IMAGE').NewValue;
Params.CreateParam(ftString, 'PID', ptInput).Value := DeltaDS.FieldByName('ID').NewValue;
SQLConnection.Execute(SQL, Params);
finally
Params.Free;
end;
end;
#2
0
Have you tried testing with another driver (e.g. ODBC)? It's possible that the error is not in your code. This approach (changing data providers/drivers) has helped me with some confusing problems that turned out not to be mine.
您是否尝试过使用其他驱动程序(例如ODBC)进行测试?错误可能不在您的代码中。这种方法(不断变化的数据提供者/驱动程序)帮助我解决了一些令人困惑的问题,而这些问题并不是我的。
#1
2
Answering my own question, the correct way to do it is the following:
回答我自己的问题,正确的方法如下:
const
SQL = 'UPDATE MYTABLE SET IMAGE = :PIMAGE WHERE ID = :PID;';
var
Params: TParams;
begin
Params := TParams.Create(nil);
try
Params.CreateParam(ftBlob, 'PIMAGE', ptInput).AsBlob := DeltaDS.FieldByName('IMAGE').NewValue;
Params.CreateParam(ftString, 'PID', ptInput).Value := DeltaDS.FieldByName('ID').NewValue;
SQLConnection.Execute(SQL, Params);
finally
Params.Free;
end;
end;
#2
0
Have you tried testing with another driver (e.g. ODBC)? It's possible that the error is not in your code. This approach (changing data providers/drivers) has helped me with some confusing problems that turned out not to be mine.
您是否尝试过使用其他驱动程序(例如ODBC)进行测试?错误可能不在您的代码中。这种方法(不断变化的数据提供者/驱动程序)帮助我解决了一些令人困惑的问题,而这些问题并不是我的。