如何从vb6中插入和检索dbf文件中的图像
我正在用VB6编写一个代码来保存和检索.dbf文件中的图像,但我不知道在dbf文件中采用什么字段类型。有人能建议我应该在dbf文件中使用哪个字段以及应该在VB6中编写什么代码吗??如何从vb6中插入和检索dbf文件中的图像,vb6,foxpro,Vb6,Foxpro,我正在用VB6编写一个代码来保存和检索.dbf文件中的图像,但我不知道在dbf文件中采用什么字段类型。有人能建议我应该在dbf文件中使用哪个字段以及应该在VB6中编写什么代码吗?? 提前感谢。我很久以前就在备忘录字段中完成了。代码是用foxpro编写的。见: CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) &&Create a table with FileName character field *并存储为备注字段
提前感谢。我很久以前就在备忘录字段中完成了。代码是用foxpro编写的。见:
CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) &&Create a table with FileName character field
*并存储为备注字段
一,
二,
它应该能解决你的问题。我很久以前就在备忘录字段中做过。代码是用foxpro编写的。见:
CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4))
*创建具有文件名字符字段的表
*并存储为备注字段
方法1:
追加空白(&a)以添加空白记录
APPEND MEMO store from "D:\Shah.Jpg" overwrite
*这将复制文件的内容。如果忽略覆盖,并且备忘录有一些内容,*文件的内容将附加到备忘录中,这应该避免
REPLACE filename WITH "Shah.Jpg"
*向其他记录添加任意数量的文件
Copy memo Store to "SomePhoto.jpg"
- 将复制到默认文件夹或
将备忘录存储复制到“c:\MyPhotos\Shah.JPG”
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*或
***这应该可以解决您的问题。这就是我在Fox pro 9中所做的,它涉及到从MYSQL服务器保存和检索图像。 1.首先按名称创建表:带有两个字段image_id(int 10)和image(longBlob)的pictures 现在我编写了两个函数SaveImage retrieveimage“
关闭数据库
使用“C:\Users\Admin\Desktop\New folder(6)\rafay.jpg”保存图像
使用“C:\KalimKhan2.jpg”检索图像
函数SaveImage
参数ImageName
&&获取图像信息
创建光标即时消息(pic Blob)
空白
覆盖`在此处输入代码`
从(ImageName)中附加备注pic覆盖
SQLDisconnect(0)
nconnect=SQLConnect('TEST_BOX','root'))
如果nconnect<0
等待窗口“连接失败!”,超时1
返回
其他的
等待窗口'已连接。'Nowait'
恩迪夫
nresult=SQLExec(nconnect,[插入图片(图像)值(?pic)])
如果nresult!=1
阿尔罗(拉尔)
将类似laErr的内存列表到文件c:\Error
错误1=.T。
=误差(x)
“等待窗口”查询失败
恩迪夫
返回“好”
函数检索图像
参数ImageName
SQLDisconnect(0)
nconnect=SQLConnect('TEST_BOX','root'))
如果nconnect<0
等待窗口“连接失败!”,超时1
返回
其他的
等待窗口'已连接。'Nowait'
恩迪夫
CursorSetProp(“MapBinary”,.T.,0)
nresult=SQLExec(nconnect,[从图片中选择*,其中图像id=1],“ImageTemp”)
如果nresult!=1
阿尔罗(拉尔)
将类似laErr的内存列表到文件c:\Error
错误1=.T。
=误差(x)
“等待窗口”查询失败
恩迪夫
nBytes=strofile(ImageTemp.Image,(ImageName))
也可以使用BLOB类型的字段并编写代码来写/读它,但如果可能的话,我建议只将图像文件名存储在文本字段中。这两种方法我都做过(很久以前)如果你弄错了一点,你就会弄乱图像。使用外部文件,你不仅不会弄乱它们,而且不会浪费时间让它们进入/离开数据库,你可以轻松地从操作系统查看它们。非常感谢。我会记住的。上帝保佑你。。。
Copy memo Store to "SomePhoto.jpg"
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")
CLOSE DATABASES
DO SaveImage WITH "C:\Users\Admin\Desktop\New folder (6)\rafay.jpg"
DO RetriveImage WITH "C:\KalimKhan2.jpg"
Function SaveImage
Parameters ImageName
&& Get image info
Create Cursor im (pic Blob)
Appen Blank
Overwrite`enter code here`
Append Memo pic From (ImageName) Overwrite
SQLDisconnect(0)
nconnect = SQLConnect('TEST_BOX','root')
If nconnect < 0
Wait Window 'Connection Failed!' Timeout 1
Return
Else
Wait Window 'Connected. ' Nowait
Endif
nresult = SQLExec(nconnect, [INSERT INTO pictures (image) VALUES (?pic) ] )
If nresult != 1
Aerror(laErr)
List Memory Like laErr To File c:\Error
error1 = .T.
=Aerror(x)
Wait Window " Query failed."
Endif
Return "good"
Function RetriveImage
Parameters ImageName
SQLDisconnect(0)
nconnect = SQLConnect('TEST_BOX','root')
If nconnect < 0
Wait Window 'Connection Failed!' Timeout 1
Return
Else
Wait Window 'Connected. ' Nowait
Endif
CursorSetProp("MapBinary",.T.,0)
nresult = SQLExec(nconnect, [Select * from pictures where image_id = 1 ],"ImageTemp" )
If nresult != 1
Aerror(laErr)
List Memory Like laErr To File c:\Error
error1 = .T.
=Aerror(x)
Wait Window " Query failed."
Endif
nBytes = Strtofile (ImageTemp.Image, (ImageName))