我想在sqlserver2000 数据库中建立一个存放图片的表:imgtable.
并向该表中添加数据.
请各位大侠给出完整的sql2000执行语句.
小弟在此thank you first!!!!!

解决方案 »

  1.   

    Function   CopyFieldToFile(rst   As   Recordset,   fd   As   String,   strFileName   As   String)   As   String   
        Dim   FileNum   As   Integer   
        Dim   Buffer()   As   Byte   
        Dim   BytesNeeded   As   Long   
        Dim   Buffers   As   Long   
        Dim   Remainder   As   Long   
        Dim   Offset   As   Long   
        Dim   r   As   Integer   
        Dim   i   As   Long   
        Dim   ChunkSize   As   Long   
        
        ChunkSize   =   65536   
        BytesNeeded   =   rst(fd).ActualSize   
              If   BytesNeeded   >   0   Then   
                    '计算buffers需要的字节数量   
                      Buffers   =   BytesNeeded   \   ChunkSize   
                      Remainder   =   BytesNeeded   Mod   ChunkSize   
                      '得到文件   
                      If   Dir(strFileName)   <>   ""   Then   
                              Kill   strFileName   
                      End   If   
                      '得到   
                      FileNum   =   FreeFile   
                      Open   strFileName   For   Binary   As   #FileNum   
                      For   i   =   0   To   Buffers   -   1   
                            ReDim   Buffer(ChunkSize)   
                            Buffer   =   rst(fd).GetChunk(Offset,   ChunkSize)   
                            Put   #FileNum,   ,   Buffer()   
                            Offset   =   Offset   +   ChunkSize   
                      Next   
                      '   复制剩下的字节到文件   
                      ReDim   Buffer(Remainder)   
                      Buffer   =   rst(fd).GetChunk(Offset,   Remainder)   
                      Put   #FileNum,   ,   Buffer()   
                      Close   #FileNum   
              End   If   
              CopyFieldToFile   =   strFileName   
      End   Function   
        
      Function   CopyFileToField(FileName   As   String,   fd   As   Field)   
        Dim   ChunkSize   As   Long   
        Dim   FileNum   As   Integer   
        Dim   Buffer()     As   Byte   
        Dim   BytesNeeded   As   Long   
        Dim   Buffers   As   Long   
        Dim   Remainder   As   Long   
        Dim   i   As   Long   
        
              If   Len(FileName)   =   0   Then   
                      Exit   Function   
              End   If   
              If   Dir(FileName)   =   ""   Then   
                      Err.Raise   vbObjectError,   ,   "File   not   found:   """   &   FileName   &   """"   
              End   If   
              ChunkSize   =   65536   
              FileNum   =   FreeFile   
              Open   FileName   For   Binary   As   #FileNum   
              BytesNeeded   =   LOF(FileNum)   
              Buffers   =   BytesNeeded   \   ChunkSize   
              Remainder   =   BytesNeeded   Mod   ChunkSize   
              For   i   =   0   To   Buffers   -   1   
                      ReDim   Buffer(ChunkSize)   
                      Get   #FileNum,   ,   Buffer   
                      fd.AppendChunk   Buffer   
              Next   
              ReDim   Buffer(Remainder)   
              Get   #FileNum,   ,   Buffer   
              fd.AppendChunk   Buffer   
              Close   #FileNum   
      End   Function
      

  2.   

    嗯,前台做是好办法后台去做,请搜索“textcopy”
      

  3.   

    看起来好复杂呀!
    我是想在SQL2000企业管理器里建表并添加数据
    行不行呀?
    如果行
    请说一下具体的步骤!
    谢谢!!
      

  4.   

    看起来好复杂呀! 
    不过还是先谢谢!!
    如果我想在SQL2000企业管理器里建表并添加数据 
    行不行呀? 
    如果行 
    请说一下具体的步骤! 
    谢谢!!
      

  5.   

    create PROCEDURE sp_textcopy ( 
      @srvname    varchar (30), 
      @login      varchar (30), 
      @password    varchar (30), 
      @dbname      varchar (30), 
      @tbname      varchar (30), 
      @photoname    varchar (30), 
      @filename    varchar (30), 
      @whereclause varchar (40), 
      @direction  char(1)) 
    AS 
    DECLARE @exec_str varchar (255) 
    SELECT @exec_str = 
            'textcopy /S ' + @srvname + 
            ' /U ' + @login + 
            ' /P ' + @password + 
            ' /D ' + @dbname + 
            ' /T ' + @tbname + 
            ' /C ' + @photoname + 
            ' /W "' + @whereclause + 
            '" /F ' + @filename + 
            ' /' + @direction 
    EXEC master..xp_cmdshell @exec_str ,no_output create table photo(id int identity(1,1),photo image,memo nvarchar(50) default 'my photo')
    go
    insert photo(photo) values(0x)    -- 必须的,且不是null
    select * from photo
    --truncate table photosp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\myphoto\roy3.jpg','where id=5','I' --注意条件是 id=1
    3、读入
    sp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\photo\21.jpg','where id=1','I' --注意条件是 id=1sp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\photo\33.jpg','where id=2','I' --注意条件是 id=2go4、读出成文件
    sp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\roy.jpg','where id=1','O' --注意条件是 id=1
    sp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\roy1.jpg','where id=2','O'
    sp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\roy2.jpg','where id=3','O'
    sp_textcopy 'roy','sa','wuxi','test','photo','photo','E:\photo\roy3.jpg','where id=4','O'sp_textcopy 'roy','sa','wuxi','test','photo','photo','c:\bb.doc','where id=5','O' --注意条件是 id=2