如何将jpg的图片加入到sql server 的 image类型的字段中阿,使用ado,谢谢
解决方案 »
- 请教一个消息的问题
- 有關edit控件的問題
- 想自己寫一個定時關機的程序,請教~!
- delphi里如何才能编程才能达到 执行Windows里,运行 执行的效果呀! (如 执行 D:\WINNT\system32\regsvr32.exe /s D:\testDll\aspcnUP.dl
- 提示"ntdll.dll"地址冲突!
- 怎样通过程序实现下载另外一台机子的文件(通过映射盘)?
- 关于怎样设置主键的讨论————欢迎参与!
- 关于实现操作系统用户管理的问题,小美求教各位大虾!!
- 关于一个读取内存地址的问题!
- 怎样编制类似于oicq的手机短讯发送程序?
- 如何将jpg的图片加入到sql server 的 image类型的字段中阿,使用ado
- 简单问题:LISTVIEW怎样添加一条记录啊!????
MStream:TMemoryStream;
begin
if not PicDlg.Execute then exit;
Screen.Cursor:=crHourGlass;
MStream:=TMemoryStream.Create;
try
MStream.LoadFromFile(PicDlg.FileName);
QryImg.Edit;
try
MStream.Position:=0;
QryImgmaterialimg.LoadFromStream(MStream);
QryImg.Post;
except
application.MessageBox('更改图片出错误!','程序提示',mb_iconstop);
end;
finally
MStream.Free;
end;
end;
表结构为三个字段ID,Nvarchar. Imame. Type,NvarcharSub SavePicture(strID As String, strFileName As String, strTable)
On Error Resume Next
Dim i As Integer
Dim lngFileLen As Long
Dim intFile As Integer
Dim Chunks As Integer
Dim Fragment As Integer
Dim Chunk() As Byte
Dim recPicture As ADODB.Recordset
Dim ChunkSize As Integer
ChunkSize = 16384
Set recPicture = rsOpen("Select Id,Picture,Type From " & strTable & " Where Id='" & Trim(strID) & "' Order By Id")
If recPicture.RecordCount = 0 Then
recPicture.AddNew
recPicture.Fields("Id") = Trim(strID)
End If
If strFileName <> "" And Dir(strFileName) <> "" Then
i = InStrRev(strFileName, ".")
If i <> 0 Then
recPicture.Fields("Type") = Mid(strFileName, i + 1)
Else
recPicture.Fields("Type") = ""
End If
intFile = FreeFile
Open strFileName For Binary Access Read As intFile
lngFileLen = LOF(intFile) ' ÎļþÖÐÊý¾Ý³¤¶È
If lngFileLen = 0 Then
Close intFile
Exit Sub
End If
Chunks = lngFileLen \ ChunkSize
Fragment = lngFileLen Mod ChunkSize
ReDim Chunk(Fragment)
Get intFile, , Chunk()
recPicture.Fields("Picture").AppendChunk Chunk()
ReDim Chunk(ChunkSize)
For i = 1 To Chunks
Get intFile, , Chunk()
recPicture.Fields("Picture").AppendChunk Chunk()
Next i
Close intFile
recPicture.Update
Set recPicture = Nothing
End If
End Sub
你的方案有错,至少你的rs有问题,如果不在open中设置光标类型,和打开方式的话,会出错