如何从vb6插入和检索dbf文件中的图像

时间:2012-10-11 13:34:18

标签: vb6 foxpro

我在VB6中编写代码来保存和检索.dbf文件中的图像,但我不知道在dbf文件中要采用什么字段类型。任何人都可以建议我应该在dbf文件中使用哪个字段以及我应该在VB6中编写哪些代码? 提前谢谢..

3 个答案:

答案 0 :(得分:1)

我很久以前就已经在Memo Fields中完成了它。代码在foxpro中。参见:

CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) &&Create a table with FileName character field

*并存储为备忘录字段

1

Append blank &&to add a blank record
APPEND MEMO store from "D:\Shah.Jpg" overwrite 
*This will copy the contents of the file. If Overwrite is ignored, and the memo has some contents,
*The contents of the file will be appended to it, which should be avoided.
REPLACE filename WITH "Shah.Jpg"
*Add as many files as you wish to other records.
Copy memo Store to "SomePhoto.jpg" && will copy to the default folder
*Or 
Copy memo store to "c:\MyPhotos\Shah.JPG" &&You must save or know the extension of the file

2

append blank
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*OR
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")

它应该可以解决你的问题。

答案 1 :(得分:1)

我很久以前就已经在Memo Fields中完成了它。代码在foxpro中。见:

CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) 

*使用FileName字符字段

创建一个表

*并存储为备忘录字段 方法1:

追加空白&&添加空白记录

APPEND MEMO store from "D:\Shah.Jpg" overwrite 

*这将复制文件的内容。如果忽略覆盖,并且备忘录包含一些内容,*文件的内容将附加到其中,应避免使用。

REPLACE filename WITH "Shah.Jpg" 

*根据需要为其他记录添加任意数量的文件。

Copy memo Store to "SomePhoto.jpg" 
  • 将复制到默认文件夹或

    Copy memo store to "c:\MyPhotos\Shah.JPG"

*您必须保存或知道文件的扩展名

方法2。

追加空白

filedata=FILETOSTR("D:\Shah.JPG") 

REPLACE store WITH filedata 

STRTOFILE(store,"SomeFileName.JPG") 

*或

STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")

***它应该可以解决你的问题。

答案 2 :(得分:0)

这就是我的工作方式在Fox pro 9中,它涉及从MYSQL服务器保存和检索图像。 1.首先按名称创建表格:带有两个字段的图片image_id(int 10)和image(longBlob)。

现在我写了两个函数SaveImage RetriveImage"

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))