function TServerMethods1.UploadPic(uName: string; uPortrait: TStream): Boolean;
//上传图片
const
BufSize = 51200;
var
Stream: TStream;
MS: TMemoryStream;
Buffer: TBytes;
ReadCount: Integer;
begin
Result := False;
Stream := uPortrait;
try
MS := TMemoryStream.Create;
if Stream.Size < -1 then
begin
SetLength(Buffer, BufSize);
repeat
ReadCount := Stream.Read(Buffer[0], BufSize);
if ReadCount > 0 then
MS.Write(Buffer[0], ReadCount);
until ReadCount < BufSize;
end
else
MS.CopyFrom(Stream, 0);
MS.Position := 0;
MS.SaveToFile('c:\users\fky\desktop\123.bmp');
// 上面的都ok
try
with sqlqry_Pic do
begin
Close;
SQL.Clear;
SQL.Add('update t_User set u_Portrait = :p_Portrait where u_Name = :p_Name');
TBlobField(Params.ParamByName('p_Portrait')).LoadFromStream(MS);
// 就是到上面这行,出现内存错误了
Params.ParamByName('p_Name').Value := uName;
ExecSQL(False);
Result := True;
end;
except
Result := False;
end;
finally
MS.Free;
end;
end;
//上传图片
const
BufSize = 51200;
var
Stream: TStream;
MS: TMemoryStream;
Buffer: TBytes;
ReadCount: Integer;
begin
Result := False;
Stream := uPortrait;
try
MS := TMemoryStream.Create;
if Stream.Size < -1 then
begin
SetLength(Buffer, BufSize);
repeat
ReadCount := Stream.Read(Buffer[0], BufSize);
if ReadCount > 0 then
MS.Write(Buffer[0], ReadCount);
until ReadCount < BufSize;
end
else
MS.CopyFrom(Stream, 0);
MS.Position := 0;
MS.SaveToFile('c:\users\fky\desktop\123.bmp');
// 上面的都ok
try
with sqlqry_Pic do
begin
Close;
SQL.Clear;
SQL.Add('update t_User set u_Portrait = :p_Portrait where u_Name = :p_Name');
TBlobField(Params.ParamByName('p_Portrait')).LoadFromStream(MS);
// 就是到上面这行,出现内存错误了
Params.ParamByName('p_Name').Value := uName;
ExecSQL(False);
Result := True;
end;
except
Result := False;
end;
finally
MS.Free;
end;
end;
解决方案 »
- DBGRIDEH改变column的visible后的事件
- fastreport问题
- 做C/S构架的管理系统,XP要不要专业版的,家庭版的行吗?
- delphi用oracle provider for ole db连接的程序,拿到另一台机子用Microsoft OLE DB Provider for Oracle连接就不行了
- 如何把异步事件变为同步,可否用回调函数实现?
- intraweb在linxu能用么?
- 要结束程序时,提示,请问这是什么问题造成的?
- 读入一个文件后(*.exe),如何查找特定的字符?(比如game),然后把这个字符之后的内容(包括game)存为一个新的文件?
- 已知某点在TForm中的坐标Point(X,Y),如何获得它在整个屏幕区域的坐标???
- 周一发薪:gzmhero(hihihi)接分
- 想做个修改按钮,delphi dbgrid怎样修改显示的记录而直接改变数据库的值
- 想做个修改按钮,delphi dbgrid怎样修改显示的记录而直接改变数据库的值
SQL.Clear;
SQL.Add('update t_User set u_Portrait =:p_Portrait where u_Name = :p_Name');
// 加一行,刷新一下参数,好像是Paramters还是Params自己试
Params.Refresh;
TBlobField(Params.ParamByName('p_Portrait')).LoadFromStream(MS);
// 就是到上面这行,出现内存错误了
Params.ParamByName('p_Name').Value := uName;
还有种方式就是,全部以SQL字串的方式来写,如:update tablename set image_field=0x010203 where image_id = id_value将Stream转换成'0x010203'类似的字符串,拼成上述格式,然后执行。