用Image字段,
function FileToDB(astrFileName, aFieldName, aTableName : string;
aConnection : TADOConnection; aCondition : string = '') : Boolean;
function BlobContentToString : string;
begin
with TFileStream.Create(astrFileName, fmOpenRead) do
try
SetLength(Result, Size);
Read(Pointer(Result)^,Size);
finally
Free;
end;
end;
var
Query : TADOQuery;
begin
Result := FALSE;
Query := TADOQuery.Create(nil);
with Query do
begin
try
Connection := aConnection;
SQL.Text := 'select ' + aFieldName + ' from ' + aTableName + ' ' +
aCondition;
Open;
if (not (EOF and BOF)) and (not FieldByName(aFieldName).IsNull) then
begin
if MessageBox(0,'是否确定抛弃原来的数据!','信息提示',
MB_OKCANCEL+MB_ICONINFORMATION+MB_TASKMODAL) = IDCANCEL then
begin
Result := False;
Exit;
end;
end;
Edit;
FieldByName(aFieldName).AsString := BlobContentToString;
Post;
Result := True;
finally
Query.Free;
end;
end;
end;