从数据库中读出的MP3是零字节 ( 积分: 100 )

  • 主题发起人 主题发起人 daisyang
  • 开始时间 开始时间
D

daisyang

Unregistered / Unconfirmed
GUEST, unregistred user!
我从数据库中读出的MP3写到某个文件夹中是零字节,不知道为什么,我把MP3写道数据库中存储MP3的字段blob变成了大写,表明我已经把MP3写到了数据库中,那就不应该是写入的问题,可我就搞不懂为什么读出来却是0字节,具体程序如下:
写入
procedure TForm4.SpeedButton1Click(Sender: TObject);
var
ms:TMemoryStream;
begin
if Edit1.Text='' then
ShowMessage('歌曲名必须填!')
else
begin
Edit1.Text:=Copy(Edit1.Text,1,10);
adoQuery1.Close;
adoQuery1.SQL.Clear;
adoQuery1.SQL.Add('Select * from AUDIO where musicname='''+Edit1.Text+'''');
adoQuery1.Open;
if not adoQuery1.IsEmpty then
begin
ShowMessage('歌曲名重复!');
Edit1.Text:=''
end else
begin
opendialog1.Execute;
if opendialog1.FileName<>'' then
begin
ms:=TMemoryStream.Create;
ms.LoadFromFile(opendialog1.FileName);
adotable1.open;
adotable1.Insert;
adoTable1['musicname']:=Edit1.Text;
adoTable1['musictype']:=combobox1.Text;
adoTable1['belongtoalbum']:=edit3.Text;
adoTable1['singer']:=Edit4.Text;
adoTable1['comment']:=Memo1.Text;
(adotable1.FieldbyName('music') as TBlobField).LoadfromStream(ms);
adoTable1.POST;
Edit1.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Memo1.Text:='';
showmessage('音乐已经插入!') ;
end;
end;
end;
end;
读出
procedure TForm4.SpeedButton2Click(Sender: TObject);
var
strSQL,MusicName,temp:String;
MusicType:String;
ms:TMemoryStream;
st:TStream;
begin

if edit4.Text='' then
showmessage('请输入要打开的音频名')
else
begin

ms:=TMemoryStream.Create;
strSQL:='select music as bblob from AUDIO where musicname ='''+Edit1.Text+'''';
with adoQuery1 do
begin
Close;
SQL.Clear;
SQL.Add(strSQL);
Active:=TRUE;
end;
st:=adoQuery1.CreateBlobStream(adoQuery1.FieldByName('bBlob'),bmRead);
ms.CopyFrom(st,st.Size);
MusicName:=edit4.Text;
MusicType:=combobox2.Text;
CreateDirectory(PChar(ExtractFilePath(ParamStr(0))+'Temp'),nil);
MusicPath:=ExtractFilePath(Application.ExeName);
MusicPath:=MusicPath+'Temp/'+MusicName+MusicType;
ms.SaveToFile(MusicPath);
showmessage(musicpath);
mediaplayer1.filename:=musicpath;
mediaplayer1.Open;
mediaplayer1.play;
end;

end;

谢谢各位帮忙拉~~!!!
 
我知道错哪了。。 当我没发过
 
后退
顶部